public static void showNotification(Context ctx, int value1, String title, String message, int value2){
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(ctx, ActivityMain.class);
int not_id = Utils.randInt(1111, 9999);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationIntent.putExtra("key_1", value1);
notificationIntent.putExtra("key_2", value2);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx.getApplicationContext());
stackBuilder.addNextIntent(notificationIntent);
PendingIntent notifPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
notificationManager.notify(not_id, createNotification(ctx, notifPendingIntent, title, message));
}
This is my code to send and display a notification
. I send this from a service. As you see there are 2 extra values that I send with the intent (key_1
and key_2
); When I click a notification I should open the activity and see the value1
and value2
of the keys.
The problem is: if another notification arrives before I open any of them, value1
and value2
are overridden. For instance:
first notification sends
foo
andbar
second notification sends
faz
andbaz
third notification send
fubar
andfobaz
So I will have 3 notifications in the bar. Now, whatever notification I click, first, second, third, I will see the values sent by the last one fubar
and fobaz
.
What I want is when I click on a specific notification, the activity display the values sent by that notification.
Any help will be highly appreciated. Thanks.
.