FVod
FVod

Reputation: 2295

PendingIntent not working on notification

I am showing multiple notifications, each notification with its own id, so all notifications are properly shown. My problem is that when clicking on the last notification, the PendingIntent used is the first one instead of the last one. I don't understand why this is happening as I'm using the FLAG_ONE_SHOT. This is the piece of code:

final PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
notificationBuilder.setContentIntent(pendingIntent);

Thanks in advance!

Upvotes: 2

Views: 1299

Answers (3)

Helmi
Helmi

Reputation: 90

change your pending intent id. use different one in place of 0

Upvotes: 1

GvSharma
GvSharma

Reputation: 2670

if you want to maintain all the notifications with unique id then this might help you.

private PendingIntent getContentIntent(String key, Context context, int currentTimeStamp) {
    Intent intent = new Intent();
    intent.setComponent(getComponentName(context));
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    return PendingIntent.getActivity(context, currentTimeStamp, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

this method will return you pending intent object

Upvotes: 0

Niranj Patel
Niranj Patel

Reputation: 33248

Use different requestCode of Pending Intent instead of "0".

final PendingIntent pendingIntent = stackBuilder.getPendingIntent(your_id, PendingIntent.FLAG_ONE_SHOT);

Upvotes: 1

Related Questions