So i used https://github.com/journeyapps/zxing-android-embedded to embedd a barcode scanner into my app. The problem is that it takes a while to start, 2 to 4 seconds. In that time the UI hangs, i added it to and AsyncTask and the UI doesn't hang anymore, but the progressdialog i added to the AsychTask does not show. when i add a thread.sleep to the doInBackground the dialog does show but hangs again when the thread.sleep is over. Anyone have an idea how to let the user know that the scanner is loading?
class loadScanner extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute(){
progress = new ProgressDialog(MainActivity.this);
progress.setTitle("Loading");
progress.setMessage("Wait while loading scanner...");
progress.setCancelable(false);
progress.setIndeterminate(true);
progress.show();
}
@Override
protected Void doInBackground(Void... params) {
integrator = new IntentIntegrator(MainActivity.this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setWide();
integrator.setOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
integrator.initiateScan();
return null;
}
@Override
protected void onPostExecute(Void result) {
progress.dismiss();
}
}
0 comments:
Post a Comment