Made the worker threads shut down synchronously to fix a race condition where the...
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 11 Apr 2008 20:25:09 +0000 (20:25 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 11 Apr 2008 20:25:09 +0000 (20:25 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@357 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android-m3/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java
android-m3/src/com/google/zxing/client/android/CameraThread.java

index 78e578f..861f449 100644 (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();
index 7ab1a86..1c36440 100644 (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();