multithreading - UI Thread block when starting zxing-android-embedded -
so used https://github.com/journeyapps/zxing-android-embedded embedd barcode scanner app. problem takes while start, 2 4 seconds. in time ui hangs, added , asynctask , ui doesn't hang anymore, progressdialog added asychtask not show. when add thread.sleep doinbackground dialog show hangs again when thread.sleep over. have idea how let user know scanner 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(); } }
move spinner code out of asynctask. put before call .execute on async task.
Comments
Post a Comment