Why the PendingIntent doesn't send back my custom Extras setup for the Intent? Why the PendingIntent doesn't send back my custom Extras setup for the Intent? android android

Why the PendingIntent doesn't send back my custom Extras setup for the Intent?


For some unspecified reason, extras will be delivered only if you've set some action, for example setAction("foo"). What CommonsWare refers to applies only when obtaining PendingIntent instances, if you haven't set FLAG_ONE_SHOT. That can be fixed by the requestCode argument in PendingIntent.get... factory methods. Although documentation says it's currently not used, it actually takes into count when distinguishing PendingIntents.

In your case, you don't need to set anything else than some dummy action string. LocationManagerService reuses the PendingIntent you have subscribed for proximity alerts, and only adds a flag if phone has entered or exited the alarm range.


If you have multiple outstanding PendingIntents, you need to make sure that the underlying Intents differ on more than their extras. Otherwise, Android will keep reusing the first PendingIntent you created for your first Intent, using that first Intent's extras all of the time.

For example, you could add a unique action via setAction() -- that will not change your Intent routing (since you are specifying the component), but it will make your Intents different.


I had this problem and the solution I found was quite simple, though I can't explain why it worked.

Initially my pending intent looked like this:

     notificationIntent = new Intent(ctx, FragmentTabsPager.class);     notificationIntent.setData(Uri.parse("content://com.sbs.mobile.workorder.WorkOrder/notes/"));     notificationIntent.putExtra("NOTIFICATION", true);        notificationIntent.putExtra(WorkOrder.WorkOrderColumns.WORKORDERID, submessage);

When creating the intent like this, no extras would be passed when the notification was clicked, the extras map would be empty in the receiving activity. I made the following change to the line initializing the notificationIntent:

     notificationIntent = new Intent().setClass(ctx, FragmentTabsPager.class);

Now the extras are populated in the receiving activity. Again, I can't explain why this works but it fixed my problem.