0

In my app, QR code scanner functions as intent to next page. Now the problem is whenever a QR code appears in front of my camera, it will keep scanning and open many many same pages. ( sry, my English is not good, hope u guys can understand the situation).

I wish it only scan one time and only open one page for me.

here is my code:

barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
    @Override
    public void release() {

    }

    @Override
    public void receiveDetections(Detector.Detections<Barcode> detections) {
        final SparseArray<Barcode> qrcodes = detections.getDetectedItems();
        if(qrcodes.size() != 0)
        {
            txtResult.post(new Runnable() {
                @Override
                public void run() {
                    //Create vibrate
                    Vibrator vibrator = (Vibrator)getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
                    vibrator.vibrate(1000);
                    txtResult.setText(qrcodes.valueAt(0).displayValue);

                    Intent intent = new Intent(User.this,Menu.class);
                    startActivity(intent);
                }
            });
        }
    }
});

Can anyone help me to fix it?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Choy
  • 452
  • 1
  • 5
  • 19
  • @user1506104 , so all i need to do is just add stop(); inside the receiveDetection? – Choy May 27 '18 at 18:31
  • @user1506104, i tried, there is no stop(); stuff – Choy May 27 '18 at 19:14
  • Possible duplicate of [How to stop scanning and store data from Google's Vision API?](https://stackoverflow.com/questions/32558923/how-to-stop-scanning-and-store-data-from-googles-vision-api) – user1506104 May 28 '18 at 04:04

2 Answers2

0

After

txtResult.setText(qrcodes.valueAt(0).displayValue);

add the following:

cameraPreview.setVisibility(View.GONE);
cameraSource.stop();
Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
0

After opening new activity than just finish the current activity. Like this

Intent intent = new Intent(User.this,Menu.class);
startActivity(intent);
finish();

Hope this will help.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50