public void quitSynchronously() {
    state = State.DONE;
    cameraManager.stopPreview();
    Message quit = Message.obtain(decodeThread.getHandler(), DecodeStatus.QUIT);
    quit.sendToTarget();
    try {
      // Wait at most half a second; should be enough time, and onPause()
      // will connectTimeout quickly
      decodeThread.join(500L);
    } catch (InterruptedException e) {
      // continue
    }

    // Be absolutely sure we don't send any queued up messages
    removeMessages(DecodeStatus.DECODE_SUCCEEDED);
    removeMessages(DecodeStatus.DECODE_FAILED);
  }