Notification in android taking same intent on clicking. I am sending notifications after installing the theme. Consider I install 4 themes and 4 notifications appear in Noti
Used this code which worked for me.
int requestCode = new Random().nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
I had the same issue, and the problem is that Android is being a little too smart and giving you the same PendingIntent
s instead of new ones. From the docs:
A common mistake people make is to create multiple
PendingIntent
objects withIntent
s that only vary in their "extra" contents, expecting to get a differentPendingIntent
each time. This does not happen. The parts of theIntent
that are used for matching are the same ones defined byIntent.filterEquals
. If you use twoIntent
objects that are equivalent as perIntent.filterEquals
, then you will get the samePendingIntent
for both of them.
Modify your code as follows to supply a unique requestCode
:
// ...
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, packageName.hashCode(), intent, 0);
// ...
This will ensure that a unique PendingIntent
is used, as opposed to the same one.
Note that hashCode()
may not be unique, so if possible use another unique integer as the requestCode
.