Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android QR Scanner: How to quit ZXingScannerView.ResultHandler to get back to where I came from

In my first steps in exploring Android I now start with QR scanning.

Works all pretty well. But I am not able to come back from the ResultHandler after read the QR successfully to my MainActivity.

public class MainActivity extends AppCompatActivity implements        
        ZXingScannerView.ResultHandler
{

  private ZXingScannerView mScannerView
  ....

  @Override
  public void handleResult(Result rawResult)
  {
   // my results are ok in rawResult
   // the scanner does not scan anymore but it is still there

   // how to go back to my main activity???
  }

  public void ClickButton (View view)
  {
       mScannerView = new ZXingScannerView(this);   

       setContentView(mScannerView);
       mScannerView.setResultHandler(this);
       mScannerView.startCamera();         
   }
}

}

I tried

mScannerview.stopCameraPreview

mScannerView.stopCamera

this.finish

setContentView(R.layout.activity_main);  // shows my activity_main 
             // but I can not click anything

Thanks!!

EDIT

I added some code to describe it a bit better. The idea is from

https://www.numetriclabz.com/android-qr-code-scanner-using-zxingscanner-library-tutorial/

like image 689
chris01 Avatar asked Mar 11 '23 05:03

chris01


1 Answers

Your question isn't clear but I'm assuming you want to restart the scan process. Normally, you'd have to restart the SurfaceHolder to be in preview mode. Luckily for you the ZXingScannerView already has a method to do that. Call mScannerView.resumeCameraPreview(this) to restart the scan process.

Otherwise can you clarify? You say you want to go back but you're already in MainActivity

like image 180
Pztar Avatar answered Apr 07 '23 05:04

Pztar