Android: after creating a new notification old

I want to create a notification without canceling or deleting previous notifications from my application. Here is my code for creating a notification:

private void notification(Context context, String title, String content) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(title) .setContentText(content); Intent resultIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); //Id allows you to update the notification later on. mNotificationManager.notify(100, mBuilder.build()); } 
+7
android notify notifications
source share
1 answer

You use hardcoded id for your notification, of course, it will replace the old one. Try using a variable id instead of hard code 100.

 mNotificationManager.notify(100+x, mBuilder.build()); 

or something like that.

+14
source share

All Articles