How to display multiple notifications in android How to display multiple notifications in android android android

How to display multiple notifications in android


just replace your line with this

 notificationManager.notify(Unique_Integer_Number, notification);

hope it will help you.


Simple notification_id needs to be changable.

Just create random number for notification_id.

    Random random = new Random();    int m = random.nextInt(9999 - 1000) + 1000;

or you can use this method for creating random number as told by tieorange (this will never get repeated):

    int m = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);

and replace this line to add parameter for notification id as to generate random number

    notificationManager.notify(m, notification);


Using Shared Preferences worked for me

SharedPreferences prefs = getSharedPreferences(Activity.class.getSimpleName(), Context.MODE_PRIVATE);int notificationNumber = prefs.getInt("notificationNumber", 0);...notificationManager.notify(notificationNumber , notification);SharedPreferences.Editor editor = prefs.edit();notificationNumber++;editor.putInt("notificationNumber", notificationNumber);editor.commit();