I have an issue on ZXing QR code inside Tabs. I have 3 fragments one of which having ZXing QR implemented and i am replacing fragments on tabs switching.I have following code in my fragment class.The main issue is when i switched tabs smoothly everything working fine. But when i switched tabs quickly again and again then CameraView became black and every Thread and AsychTask of Application stopped working.This issue is destroying my whole application.
Here is code of Fragment's OnResume method. ScanningThread is a class extended with Thread and scannerView is a custom CameraView class.
ScanningThread scanningThread = new ScanningThread();
scanningThread.setScanListener(scanListener);
scannerView.onResume();
scannerView.setPreviewCallback(scanningThread);
scanningThread.start();
Here is code of onPause method.
this.scannerView.onPause();
this.scanningThread.stopScanning();
Here is my setPreviewCallBack method of CameraView class:
public void setPreviewCallback(final @NonNull PreviewCallback previewCallback) {
enqueueTask(new PostInitializationTask<Void>() {
@Override
protected void onPostMain(Void avoid) {
if (camera.isPresent()) {
camera.get().setPreviewCallback(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (!CameraView.this.camera.isPresent()) {
return;
}
final int rotation = getCameraPictureOrientation();
final Size previewSize = camera.getParameters().getPreviewSize();
if (data != null) {
previewCallback.onPreviewFrame(new PreviewFrame(data, previewSize.width, previewSize.height, rotation));
}
}
});
}
}