How to handle multiple notification in android?

Many time we would send multiple notification to users in a short time,
and you can handle “more than one” unread notification at a time in your Android application.

Here I explian you the simple tips to handle multiple notifications in your Android application.

I solved this problem in Android version 3.0.

The demo code when generate notification :

NotificationManager demonotification = (NotificationManager)


Notification notification = new Notification(icon, message, when);

String title = context.getString(R.string.app_name);//The notification title

Date now = new Date();

long uniqueId = now.getTime();

Note:-Fill the information whatever you pass in your notification to the intent.
Change the HomeActivity and class name what you wish to start when user click on the notificaiton..

Intent notificationIntent = new Intent(context, HomeActivity.class);

notificationIntent.putExtra(“IS_NOTIFICATION”, true);
notificationIntent.putExtra(“NOTIFICATION_MSG”, message);

Note:-if u dosen’t need to strat new activity must set Intent.

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |

Note:-if you want to represent your notification so you cought use unique string.
But remember that tha each and every notification have difference action name..

notificationIntent.setAction(“com.sample.myapp” + uniqueId);

PendingIntent intent =PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;

Note:- How to Play default notification sound?
notification.defaults |= Notification.DEFAULT_SOUND;
notification.sound = Uri.parse(“android.resource://” + context.getPackageName() +
Note:- When vibrate is enabled.and you want a vibrate
notification.defaults |= Notification.DEFAULT_VIBRATE;
Note:-If you use the same uniqueId for each notification, the Notification Manager will assume that is same notification and would replace the previous notification. **/
notificationManager.notify((int) uniqueId, notification);
I hope you are easily understand this code and enjoy android development.
Thank you…

About the Author