Made the worker threads shut down synchronously to fix a race condition where the CameraManager could close the camera driver too soon.

git-svn-id: https://zxing.googlecode.com/svn/trunk@357 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-04-11 20:25:09 +00:00
parent e14defda5f
commit 4c10031a67
2 changed files with 14 additions and 2 deletions

View file

@ -91,8 +91,7 @@ public final class BarcodeReaderCaptureActivity extends Activity {
protected void onPause() {
super.onPause();
if (cameraThread != null) {
Message quit = Message.obtain(cameraThread.handler, R.id.quit);
quit.sendToTarget();
cameraThread.quitSynchronously();
cameraThread = null;
}
cameraManager.closeDriver();

View file

@ -76,6 +76,10 @@ final class CameraThread extends Thread {
state = State.DONE;
Message quit = Message.obtain(decodeThread.handler, R.id.quit);
quit.sendToTarget();
try {
decodeThread.join();
} catch (InterruptedException e) {
}
Looper.myLooper().quit();
break;
case R.id.decode_started:
@ -116,6 +120,15 @@ final class CameraThread extends Thread {
Looper.loop();
}
public void quitSynchronously() {
Message quit = Message.obtain(handler, R.id.quit);
quit.sendToTarget();
try {
join();
} catch (InterruptedException e) {
}
}
public void setDecodeAllMode() {
Message message = Message.obtain(decodeThread.handler, R.id.set_decode_all_mode);
message.sendToTarget();