Not Able To Identify Id For Item Clicked On Notification
Solution 1:
You are using the same PendingIntent
with all your notifications, even if you think otherwise. This is actually clearly documented here:
If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel() to remove it.
Because of this behavior, it is important to know when two Intents are considered to be the same for purposes of retrieving a PendingIntent. A common mistake people make is to create multiple PendingIntent objects with Intents that only vary in their "extra" contents, expecting to get a different PendingIntent each time. This does not happen.
To solve this you need to provide i.e. different requestCode, so insead of
PendingIntentcontentIntent= PendingIntent.getActivity(this, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
you should write
PendingIntentcontentIntent= PendingIntent.getActivity(this, NOTIFICATION_ID,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Solution 2:
The flag FLAG_UPDATE_CURRENT here:
PendingIntentcontentIntent= PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent. For use with getActivity(Context, int, Intent, int), getBroadcast(Context, int, Intent, int), and getService(Context, int, Intent, int).
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.
Means that the last one you create will replace all the previous one. To avoid that, you must make them different according to the criteria that IntentFilter uses:
There are three Intent characteristics you can filter on: the action, data, and categories
You are using the same action and category, and don't specify data. It will not use whatever you put in Extras for filtering them. My suggestion that instead of this:
notificationIntent.putExtra("invoiceList", data1);
You turn data1
somehow into a Uri, and Intent.setData()
to store it.
Post a Comment for "Not Able To Identify Id For Item Clicked On Notification"