Notification passes old Intent Extras Notification passes old Intent Extras android android

Notification passes old Intent Extras


You are sending the same request code for your pending intens.Change this:

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

To:

PendingIntent contentIntent = PendingIntent.getActivity(context, UNIQUE_INT_PER_CALL, notificationIntent, 0);

intents are not created if you send the same params. They are reused.


Alternatively, you can use the following code to generate your PendingIntent:

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

From the doc for PendingIntent.FLAG_UPDATE_CURRENT:

If the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent. This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.


You are passing the same ID. In this kind of situation, make a unique id from time like this:

int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);

And put it as this:

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),iUniqueId, intentForNotification, 0);