所以我用https://github.com/journeyapps/zxing-android-embedded將條碼掃描器嵌入到我的應用程序中。問題在於它需要一段時間才能開始,2到4秒。在那段時間,用戶界面掛起,我將它添加到AsyncTask中,用戶界面不再掛起,但我添加到AsychTask中的progressdialog不顯示。當我添加一個thread.sleep到doInBackground時,對話框會顯示,但在thread.sleep結束時會再次掛起。任何人都有一個想法如何讓用戶知道掃描儀正在加載?UI線程塊啓動時zxing-android-embedded
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();
}
}
似乎不是這樣做。 – user2463163 2015-04-01 19:58:24
Somehow integrator.initiateScan();阻止了用戶界面 – user2463163 2015-04-01 20:07:22