Re: IntentIntegrator.addExtra() not working

1,073 views
Skip to first unread message

Sean Owen

unread,
Jul 13, 2012, 7:01:30 AM7/13/12
to zx...@googlegroups.com
I don't think there's a problem here -- look at the source. It definitely gets attached in attachMoreExtras(). You probably need to have a look with a debugger to see why you're not reading the intent on the other side or not setting it as you think.

Simonetti

unread,
Jul 13, 2012, 12:14:09 PM7/13/12
to zx...@googlegroups.com
First of all, thanks for the reply, Sean.
 
I created a very simple test app, with an ImageButton + an EditText just to check the feature of putExtra. The button uses IntentIntegrator to call Barcode Scanner (4.2), sets 3 pair-values in  extras and then makes the call which scans a simple EAN barcode.
 
I am using intenet.getExtras().keySet() to see whatever is returned from the intent, and only the pairs set by Barcode Scanner are returned.
 
It still worked like before: on the onActivityResult, the Intent object passed to the call doesn't have any of the extras I set when I called the intent.
 
The value I am passing is a String, if that matters.
 
 
 

Sean Owen

unread,
Jul 13, 2012, 4:36:39 PM7/13/12
to zx...@googlegroups.com
The extras don't come back to you from Barcode Scanner; they are sent to Barcode Scanner. They don't somehow also get copied back to you -- the caller presumably already has that info.

Simonetti

unread,
Jul 16, 2012, 6:22:31 PM7/16/12
to zx...@googlegroups.com

So please explain this to me: 

 
Calling code:

IntentIntegrator integrator =  new IntentIntegrator(this);
 integrator
.addExtra(Utils.EXTRA_MODO, "find");
 integrator
.addExtra(Utils.EXTRA_MODO+"1", 0);
 integrator
.addExtra(Utils.EXTRA_MODO+"2", new String("find"));
 integrator
.addExtra(Utils.EXTRA_MODO+"3", "find");
 integrator
.initiateScan();

 
Then the receiving onActivityResult I have:
 
    (...)  
   
Bundle extras = intent.getExtras();
   
   
for (String key : extras.keySet())
       
Log.i("KEY_" + key, "value: " + extras.get(key).toString());
   
(...)


(I tried pasting the whole function but this crappy parser of google Groups won`t format the code properly).
 
 

This is what I get as output (ADB log):

07-16 19:10:44.820: I/KEY_SCAN_RESULT(15500):                                     value: 740617166453
07-16 19:10:44.825: I/KEY_SCAN_RESULT_FORMAT(15500):                   value: UPC_A

And nothing else. My point is that since the Integrator Uses the Bundle to return data back to the calling Activity, it IS OVERWRITING whatever I wrote to the extras.

Can you at least try what I have been saying instead of just assuming your code is correct?

 

 

 

 

 

 

 



 

 

 

 

Sean Owen

unread,
Jul 17, 2012, 2:27:54 AM7/17/12
to zx...@googlegroups.com
I'm not assuming mate, I've tested it, as per the second message. I believe you're still misunderstanding the sequence of Intents here.

You are talking about onActivityResult(). This is something that the *calling* activity implements. As I said before, your key/value pairs are not returned back to the caller in the Bundle. Your key/value messages are from caller to Barcode Scanner. Barcode Scanner sets a bunch of different stuff in the reply, as the result. 

I do not see a reason why you need EXTRA_MODO to be sent *back* to the caller. The caller already has this information in the first place, in order to send it. Barcode Scanner is also not going to do anything with your custom keys.

It is not "overwriting" anything. The Bundle is not somehow preserved by Android for reuse between the Intent invocation and the reply. These are separate messages.

Sean Owen

unread,
Dec 23, 2012, 5:16:33 AM12/23/12
to zx...@googlegroups.com
You should store that information in your app. There's no real need to send it off and read it back.

Lachezar Dobrev

unread,
Dec 23, 2012, 5:17:56 AM12/23/12
to zxing
*resending to list, as GMail sent it to a member only*

The common solution to this problem is to store the ID of the record
you're trying to attach to in your activity (and store/restore it in
onSaveInstanceState/onRestoreInstanceState), and then use it in
onActivityResult().
AFAIK there is no Android sanctioned requirement or suggestion for
an activity to return elements from the call intent.

2012/12/23 Sławomir Bretes <br3...@gmail.com>:
> Hi!
>
> I see a reason why sometimes we need EXTRAS to come back. I'm also having a
> huge problem with Integrator because in my app i'm trying to attach barcode
> to database record. When i put record id in extra field then i don't have it
> when the barcoed is readed. In result i can't update record and attach
> barcode, record id is gone.
>
> Please help.
> --
>
>
>

PJFonseca

unread,
Dec 23, 2013, 10:13:28 AM12/23/13
to zx...@googlegroups.com
You are the man! 

You are so right about this... Your response just helped me, i was on loop mode :)
Reply all
Reply to author
Forward
0 new messages