diff --git a/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java b/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java index 5beba81..7448655 100644 --- a/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java +++ b/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java @@ -33,6 +33,7 @@ public class BarcodeScanner extends Plugin implements BarcodeCallback { private boolean didRunCameraSetup = false; private boolean didRunCameraPrepare = false; private boolean isBackgroundHidden = false; + private String actionOnResume = null; private boolean hasCamera() { // @TODO(): check: https://stackoverflow.com/a/57974578/8634342 @@ -82,7 +83,7 @@ private void setupCamera() { didRunCameraSetup = true; } - private void dismantleCamera() { + private void dismantleCamera(Boolean freeSavedCallFlag) { // opposite of setupCamera getActivity() @@ -101,7 +102,7 @@ private void dismantleCamera() { didRunCameraPrepare = false; // If a call is saved and a scan will not run, free the saved call - if (getSavedCall() != null && !shouldRunScan) { + if (freeSavedCallFlag && getSavedCall() != null && !shouldRunScan) { freeSavedCall(); } } @@ -109,7 +110,7 @@ private void dismantleCamera() { private void prepare() { // undo previous setup // because it may be prepared with a different config - dismantleCamera(); + dismantleCamera(true); // setup camera with new config setupCamera(); @@ -125,7 +126,7 @@ private void prepare() { private void destroy() { showBackground(); - dismantleCamera(); + dismantleCamera(true); } private void scan() { @@ -200,6 +201,25 @@ public void barcodeResult(BarcodeResult barcodeResult) { destroy(); } + @Override + public void handleOnPause() { + if (isScanning) { + actionOnResume = "scan"; + } else { + actionOnResume = null; + } + dismantleCamera(false); + } + + @Override + public void handleOnResume() { + if (actionOnResume != null) { + if (actionOnResume.equals("scan")) { + scan(); + } + } + } + @Override public void possibleResultPoints(List resultPoints) {}