b.i
b.i

Reputation: 1107

Android: new information replace old information in notification

From the documenation of the NotificationManager in Android:

public void notify (int id, Notification notification) 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.

it will be replaced by the updated information.

I don't want the old information to be replaced, I want both notifications. NB: each notification has its own id:

notificationManager.notify(0, notification);
notificationManager.notify(1, notification);

How to do this?

Upvotes: 2

Views: 4239

Answers (3)

Sarojini2064130
Sarojini2064130

Reputation: 221

Try this one:

private void notifyMe(String message) {
        NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
        ncomp.setContentTitle(getResources().getString(R.string.notification_title));
        ncomp.setContentText(message);
        ncomp.setTicker(getResources().getString(R.string.notification_ticker));
        ncomp.setSmallIcon(R.drawable.ic_launcher);
        ncomp.setAutoCancel(true);      
        //nManager.notify((int) System.currentTimeMillis(), ncomp.build());
        nManager.notify(int(System.currentTimemillisec
), ncomp.build());
    }

Upvotes: 0

micahli123
micahli123

Reputation: 480

Stack your notifications

If your app creates a notification while another of the same type is still pending, avoid creating an altogether new notification object. Instead, stack the notification.

A stacked notification builds a summary description and allows the user to understand how many notifications of a particular kind are pending.

http://developer.android.com/design/patterns/notifications.html

Upvotes: 2

Anders Metnik
Anders Metnik

Reputation: 6237

public void notify (String tag, int id, Notification notification)

Since: API Level 5 Post a notification to be shown in the status bar. If a notification with the same tag and id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.

Parameters tag A string identifier for this notification. May be null. id An identifier for this notification. The pair (tag, id) must be unique within your application. notification A Notification object describing what to show the user. Must not be null.

Upvotes: 0

Related Questions