Reputation: 1117
I am creating a notification system that pushes multiple notifications through a FOR loop. Logcat shows that I am creating multiple notifications (The phone even sends two ringtones corresponding to each one). But the notification bar only shows the last one. I read the documentation and it says that calling NotificationManager.notify takes a unique Id and if this Id exists, then the notification will be replaced with the new one. I used a unique GUID for each notification but still no success.
notificationManager.notify(notification.getInt("id"), n);
Any suggestions I can work with? Could it be the PendingIntent part of the notification?
Thanks in advance.
Upvotes: 3
Views: 4547
Reputation: 59
Please Check the Pending Intent request code, that should be unique for each cycle of loop.
Upvotes: 0
Reputation: 15
You have to make a new intent, just add the following piece of code:
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
You need to setFlag in notification also:
n.flags += Notification.FLAG_ONGOING_EVENT;
n.flags += Notification.FLAG_NO_CLEAR;
notificationManager.notify(notificationId, n);
Please refer the link : Android: Managing Multiple Notifications
Upvotes: 1
Reputation: 532
just make sure you are using unique id, as a work around you can use for loop integer i value instead of notification.getInt("id").
eg:
for(int i = 1; i < 10; i++)
{
notificationManager.notify(i, n);
}
or you can save an integer value in SharedPrefrence and increment it regularly in for loop and using the same as id.
Upvotes: 7