0

所以我用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(); 
    } 
} 

回答

0

将微调代码移出您的AsyncTask。 在异步任务中调用.execute之前先放置它。

+0

似乎不是这样做。 – user2463163 2015-04-01 19:58:24

+0

Somehow integrator.initiateScan();阻止了用户界面 – user2463163 2015-04-01 20:07:22

0

我有同样的问题!

修复它与更新zxing版本!

随着摇篮只是把论文depence:

compile 'com.journeyapps:zxing-android-embedded:[email protected]' 
compile 'com.google.zxing:core:3.2.1'