Skip to content
Advertisement

Android: pass data from initial activity (launching Zxing scanner) to onActivityResult callback

I use the library zxing-android-embedded in my Android App. Before calling initiateScan() method to start the scanner from my activity, I set a class variable scanedItemId to know on which item I clicked to scan:

JavaScript

Then I get the result via onActivityResult method. It works well but my class variable scanedItemId is null because the activity is relaunched. Is it possible to keep my initial instance of MyActivity (with the scanedItemId well set) or to pass the value I need thru the IntentIntegrator to get it back on the new instance of MyActivity?

JavaScript

If possible I wouldn’t like to use a hard persistence (like db or file) to get my scanedItemId value.

Hope it’s clear enough

Advertisement

Answer

You can add more custom data like this :

JavaScript

Because library which you used didn’t return your data. You can fork that library and add some code like below:

In CaptureManager class edit initializeFromIntent method

JavaScript

and resultIntent method

JavaScript

Now in onActivityResult you can get your data

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement