Android multiple notification

I have an application in which the user can create events and set notifications for this event itself. So I want to add some notifications. I am using the following code.

final Notification notifyDetails = new Notification(R.drawable.icon, "Myapp",calendar.getTimeInMillis()); Context context = getApplicationContext(); Intent notifyIntent = new Intent(context, ViewDoughnut.class); PendingIntent pendingIntent = PendingIntent.getActivity(ViewCal.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); notifyDetails.setLatestEventInfo(context, contentTitle, contentText, pendingIntent); notifyDetails.flags = Notification.FLAG_ONGOING_EVENT; mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); 

When I add an event and create a notification using the above code, it works fine. But if I add another event, a new notification will not be created, the old one will only be updated. I want to add another notification. How to do it? Moreover, I want to delete any specific notification if the user deletes the corresponding event. How is this possible?

+7
source share
2 answers

I suppose SIMPLE_NOTIFICATION_ID is a constant? To have separate notifications, you need to use a different identifier for each.

+12
source

Below is the code for the unique pass identifier identifier:

 //"CommonUtilities.getValudeFromOreference" is the method created by me to get value from savedPreferences. String notificationId = CommonUtilities.getValueFromPreference(context, Global.NOTIFICATION_ID, "0"); int notificationIdinInt = Integer.parseInt(notificationId); notificationManager.notify(notificationIdinInt, notification); // will increment notification id for uniqueness notificationIdinInt = notificationIdinInt + 1; CommonUtilities.saveValueToPreference(context, Global.NOTIFICATION_ID, notificationIdinInt + ""); //Above "CommonUtilities.saveValueToPreference" is the method created by me to save new value in savePreferences. 

Let me know if you need more information or any request. :)

0
source

All Articles