I am using push notifications in my app. I need to display a notification when a push notification delivered. If I send another notification (without clearing the previous notif
Use a new notification ID every time instead of hardcoding to 1:
int i = x; //Generate a new integer everytime
mNotificationManager.notify(i, notification);
You can also use System.currentTimeMillis() to assign unique id to your notification.
int id = (int) System.currentTimeMillis();
mNotificationManager.notify(id, notification);
I am not sure what your use case is, but the Android design guidelines recommend not doing it at all.
Don't: Do:
We need Unique notification id which will generate the new notifications.
Post a notification to be shown in the status bar. If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.
@param id An identifier for this notification unique within your application.
@param notification A {@link Notification} object describing what to show the user.
Must not be null.
public void notify(int id, Notification notification)
{
notify(null, id, notification);
}
Example :
int id =(int) System.currentTimeMillis();
mNotificationManager.notify(id, notify);
simple you have to
change Notification id
mNotificationManager.notify(1, notification);
instead of 1
for more refer this Link
You need to supply a different ID as the notification ID each time. The best approach would be to send an ID field to GCM which can be then accessed via Intent.getExtras().getInt()
in your GCMIntentService's onMessage() method.
If this is not possible, I'd suggest using something like (int)Math.random()*10
to generate a random integer number as your notification ID. This will (partially) ensure that your notifications will not replace each other.