Issue
Update: Neither eclipse nor the code did cause these trouble. Genymotion did.
Maybe my approach is completely wrong, since no one else seems to have this problem - if so, i am open to try different ways rather then fix this problem: I have the following setting.
A BroadcastReceiver is listening for installations of Apps. Whenever a new App is installed, I create a Notification, using a PendingIntent that is based on a normal Intent via
PendingIntent pIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Before the PendingIntent is created, I put some extras in the normal Intent, that shall be passed to the Activity which is triggered, when the notification is clicked.
notificationIntent.putExtra("AppLabel", appLabel); // the installed App
notificationIntent.putStringArrayListExtra("Group", group); // the corresponding group
notificationIntent.putStringArrayListExtra("List", list); // the corresponding list
Now this works fine and the notification is displayed. Debugging I can see, that when pIntent is created, all extras are set correctly and passed. However, when I try to read the extras in the opened Activity trouble starts. I already had to build a workaround, based on an answer here, to read the extras:
Bundle bundle = getIntent().getExtras();
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if (key.equals("Group")) {
group = (ArrayList<String>) value;
} ... }
This also worked for a time, but now i am completely lost. For some Reason, the ArrayList extras are empty [] - the appLabel is still set correctly.
Now the real trouble is, that I am not sure if this is code related, or an eclipse issue.
I observed, that after some deployments, the bundle.keySet() returned different keys then I had set in the putExtra call. I also encounter OutOfSync errors often when I search. Refreshing does help some times, regarding the names of the keys, but the values are lost still.
To anyone who has read this: many thanks! now - has somebody a clue, what is going on here? Does anyone know similar eclipse problems? Or is there an error in the code? Any proposals for a different design are welcome as well. I'd be just glad, if I can exclude some error sources... Thanks in advance
Update: Manifest Infos: The launched notification Activity is defined like:
<activity
android:theme="@style/Theme.AppCompat.CompactMenu.Dialog"
android:label="Notification Receiver"
android:excludeFromRecents="true">
</activity>
The MainActivity however has just a name and a label. Besides:
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />
I just added a SystemOut at two points: One when the intent is created by the BCR, one when it is read by the Activity.
BroadcastReceiver.getExtras.keyset returns [a,b,c,d]
Activity.getExtras.keyset returns the keys [x,y,z]
Searching in all Projects and all Workspace, x,y,z are nowhere to be found... They were used in a previous version of some days ago, so it seems eclipse stored some invalid old data?
Solution
Well, looks like all the technical stuff and all the outOfSync was nasty, but in the end not relevant. It just covered a very trivial mistake. The answere can be found here: Incorrect extras received with all intents but the first one
At least for the current implementation, this looks like solving the problems - except for the sync issues of course but that has not occured again.
Answered By - D4ngle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.