Reputation: 729
In Android, when you get the same type of push notification, the most recent one replaces the previous one in your notification screen, mostly likely to prevent clutter. However, I saw that in some apps, I get separate notifications from the same app that do not replace the previous notification. How do I program my app to do that?
Upvotes: 0
Views: 954
Reputation: 1885
In order for having multiple notifications on the status bar, all you have to do is set a unique notification ID for every notification you want. If you send two notifications with the same ID, the notification manager replaces the oldest one with the newest. Have a look in Notification Manager's notify method.
Here's an example of how to send a notification:
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(alarmSound)
.setPriority(Notification.PRIORITY_MAX)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId, notification);
Make sure notificationId
is unique, otherwise it'll replace the oldest notification with the same ID.
Upvotes: 2