0

I am new to android development

I use this QR code scanner library

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        CodeScannerView scannerView = findViewById(R.id.scanner_view);
        mCodeScanner = new CodeScanner(this, scannerView);
        mCodeScanner.setDecodeCallback(new DecodeCallback() {
            @Override
            public void onDecoded(@NonNull final Result result) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(MainActivity.this, result.getText(), Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
        scannerView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCodeScanner.startPreview();
            }
        });       
    }

I am able to get the qr code result in onDecoded method for once successfully.

I need to scan QR multiple times so I tried using for loop, but my need is wait for the first QR to be scanned, and then go for next scan.

for(int i =0;i<10;i++) {
   mCodeScanner.startPreview();
   // wait for first QR to finish scanning and then go for next iteration
}

I tried using wait() and notify() but it simply crashes on wait() statement without any error throwing How to notify another thread

James Z
  • 12,209
  • 10
  • 24
  • 44
Raize Ahamed
  • 13
  • 1
  • 4
  • I was using this library . I have changed to MLKit QR - it works much better https://developers.google.com/ml-kit/vision/barcode-scanning/android – kfir Jul 28 '23 at 12:30

1 Answers1

0

I need to scan QR multiple times...

Why not start each next scan from within the onDecoded callback?

I tried using wait() and notify() but it simply crashes...

If you are asking what went wrong there, then you should show the code that crashes in your question.

Solomon Slow
  • 25,130
  • 5
  • 37
  • 57