I've created a test project with three identical classes that extend
BroadcastReceiver, named
TestReceiverOne
TestReceiverTwo
TestReceiverThree
They each have the following function as their content:
@Override
public void onReceive(Context context, Intent intent) {
Bundle result = getResultExtras(false);
if(result == null) {
result = new Bundle();
}
int numResults = getResultCode();
numResults++;
setResultCode(numResults);
result.putByteArray("result" + (numResults),
this.getClass().getName
().getBytes());
setResultExtras(result);
}
Additionally, my test Activity has the following code:
sendOrderedBroadcast(i, null, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle results = getResultExtras(true);
int numResults = getResultCode();
tv.setText("" + numResults + " results");
for(String key : results.keySet())
tv.setText(tv.getText() + "\n" + key + ": " +
new String
(results.getByteArray(key)));
tv.invalidate();
}
}, null, 0, null, null);
I've added each BroadcastReceiver class to the manifest, have it
accept the appropriate action/category, and start debugging. I've set
breakpoints in the onReceive method of each test class, and in the
anonymous inner BroadcastReceiver in my onCreate.
Unfortunately, I seem to be getting somewhat undefined behavior.
Sometimes getResultExtras in my second onReceive will return null.
Sometimes getResultCode in the second onReceive returns 0. Sometimes
I'm 1 off in my third onReceive. Sometimes I get the wrong numResults
in onReceive in my activity.
What am I missing here? Is there some other behavior I have to specify
when using setResult and getResult in an ordered broadcast?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---