Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple notifications to the same activity

I have an activity that is being opened from the notification bar, but when I do NotificationManager.notify(...), I'm giving to the intent a different bundle, so that each notification opens the same activity, but obtaining from the DB other information each other.

But when I try to enter to any of the notifications (for example there are 3 notifications), they all send me to the activity with the same bundle that the last one. After trying with some Flags, I really don't know where is the problem (some flags makes the notification enter to the activity with the first bundle).

I'm following the way they used it in the tutorial.

like image 794
Daniel Avatar asked May 20 '11 00:05

Daniel


People also ask

How do I manage multiple notifications on Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.


Video Answer


1 Answers

If the PendingIntent has the same operation, action, data, categories, components, and flags it will be replaced.

Depending on the situation i usually solve this by providing a unique request code either as static values (0,1,2) or the row id of the data I'm receiving from the DB.

PendingIntent.getActivity(context, MY_UNIQUE_VALUE , notificationIntent, PendingIntent.FLAG_ONE_SHOT); 

Then I use the same unique value for notify() as

mNotificationManager.notify(MY_UNIQUE_VALUE, notification); 
like image 103
rochdev Avatar answered Sep 30 '22 13:09

rochdev