Made the worker threads shut down synchronously to fix a race condition where the...
[zxing.git] / android-m3 / src / com / google / zxing / client / android / CameraThread.java
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();