Still Image Image for Android Barcodes with Multiple ZXingScannerView

In my application, I have a snippet using dm77 / barcodescanner .

I’m working on a store application, for example: you are viewing an item → a product page → continue the purchase → open another scanner session → etc.

Now, as you can see, because the client needs to support the back stack, several events of this fragment can be opened (but not at the same time).

The first fragment with the scanner works well, the rest have a still image, even if I call

scannerView.stopCamera();
scannerView = null;

leaving the first fragment.

NOTE: another snippet works well if we use replace instead of adding. But this will create problems with the animation of the fragments.

+4
source share
1 answer

After furious debugging, I discovered how everything works:

  • When the fragment is visible / used, create and add ZXingScannerView programmatically in your layout, starting with the camera and preview;
  • When the fragment is not displayed / used, remove the ZXingScannerView from your layout;
  • In some versions of Android (for example, 5.01), be careful not to call it startCameramore than once, otherwise you won’t be able to open it until you restart the application. The error here is caused by the exception of a dead thread.

Hope that was clear and useful enough.

+2
source

Source: https://habr.com/ru/post/1660186/


All Articles