title: How to stop continuous scanning by zxing-android-embedded in Android
body: <p>I am using <strong>Zxing-android-embedded</strong>(<a href="https://github.com/journeyapps/zxing-android-embedded" rel="noreferrer">https://github.com/journeyapps/zxing-android-embedded</a>) to scan QR codes. I have imported the library from github . When the app starts , the camera is scanning the code repeatedly as long as the camera is placed on a barcode.<strong>I want to stop the scanning(but not the camera preview)</strong> once the barcode is detected and show a dialog box with "Confirm" button, "Cancel" button, and a input box. When user press the "Confirm" or "Cancel" button it should start scanning again. </p>
  
  <p>I have called <code>barcodeView.pause();</code> at the beginning of the decode() method which pauses the camera preview. Also, added <code>barcodeView.resume();</code> inside onClick method of "dialogConfirmClick" and "dialogCancelClick". But <code>barcodeView.pause();</code> method pauses scanning as well as the camera preview.</p>
  
  <p>Here is my class-</p>
  
  <pre><code>public class MyScanActivity extends Activity {
      private static final String TAG = MyScanActivity.class.getSimpleName();
  
      private CompoundBarcodeView barcodeView;
      private BeepManager beepManager;
      private DialogInterface.OnClickListener dialogCanselClick;
      private AlertDialog dialog;
  
      private BarcodeCallback callback = new BarcodeCallback() {
          @Override
          public void barcodeResult(BarcodeResult result) {
              if (result.getText() != null) {
                  handleDecode(result);
              }
          }
  
          @Override
          public void possibleResultPoints(List&lt;ResultPoint&gt; resultPoints) {
          }
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Window window = getWindow();
          window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
          setContentView(R.layout.continuous_scan);
          barcodeView = (CompoundBarcodeView) findViewById(R.id.barcode_scanner);
          barcodeView.decodeContinuous(callback);
          beepManager = new BeepManager(this);
          dialogCancelClick = new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  barcodeView.resume();//Resume scanning 
                  dialog.dismiss();
              }
          };
      }
  
      public void handleDecode(BarcodeResult rawResult) {
          barcodeView.pause();//Pause preview
          String result = rawResult.getText();
  
          beepManager.playBeepSoundAndVibrate();
  
          DialogInterface.OnClickListener dialogOkClick = new DialogInterface.OnClickListener() { // OK
              // button
              @Override
              public void onClick(DialogInterface dialog, int which) {
  
                  if (writeNote) {
                      EditText txtNote = (EditText) promptsView.findViewById(R.id.txt_dialog_note);
                      //code to merge value of txtNote with result
                  }
  
                  dialog.dismiss();
                  barcodeView.resume();//Resume scanning after pressing confirm button
                  Toast.makeText(MyScanActivity.this, R.string.dialog_save_qr_alert, Toast.LENGTH_SHORT).show();
              }
          };
  
          AlertDialog dialog = DialogHelper.CreateDialog(this, DialogHelper.SAVE_QR_CODE, result, dialogOkClick, dialogCancelClick, promptsView);
          dialog.show();
      } 
  
      @Override
      protected void onResume() {
          super.onResume();
  
          barcodeView.resume();
      }
  
      @Override
      protected void onPause() {
          super.onPause();
  
          barcodeView.pause();
      }
  
      public void pause(View view) {
          barcodeView.pause();
      }
  
      public void resume(View view) {
          barcodeView.resume();
      }
  
      public void triggerScan(View view) {
          barcodeView.decodeSingle(callback);
      }
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          return barcodeView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
      }
  }
  </code></pre>