This is the case, using Notificationmanager to trigger multiple notification:
Java code
- Private Notification genrenotification (context context, int icon, string tickertext, string title, string content, int Ent Intent) {
- Notification Notification = new Notification (icon, Tickertext, System.currenttimemillis ());
- Pendingintent pendintent = pendingintent.getactivity (context, 0, intent, pendingintent.flag_update_current);
- Notification.setlatesteventinfo (context, title, content, pendintent);
- Notification.flags |= Notification.flag_auto_cancel;
- return notification;
- }
- ...
- Mnotificationmanager.notify (Id_1,
- Genrenotification (Mcontext, Icon_res,
- NotifyText1, NotifyTitle1, NotifyText1, intent_1));
- ...
- Mnotificationmanager.notify (Id_2,
- Genrenotification (Mcontext, Icon_res,
- NotifyText2, NotifyTitle2, NotifyText2, intent_2));
- ...
- Mnotificationmanager.notify (Id_3,
- Genrenotification (Mcontext, Icon_res,
- NOTIFYTEXT3, NotifyTitle3, NotifyText3, intent_3));
Private Notification genrenotification (context context, int icon, string tickertext, string title, string content, Intent Intent) {Notification Notification = new Notification (icon, Tickertext, System.currenttimemillis ()); Pendingintent pendintent = pendingintent.getactivity (context, 0, intent, pendingintent.flag_update_current); Notification.setlatesteventinfo (context, title, content, pendintent); Notification.flags |= Notification.flag_auto_cancel; return notification; }...mnotificationmanager.notify (Id_1, Genrenotification (Mcontext, Icon_res, NotifyText1, NotifyTitle1, NotifyText1, intent_1) ... mnotificationmanager.notify (id_2, genrenotific ation (Mcontext, Icon_res, NotifyText2, NotifyTitle2, NotifyText2, intent_2)) ... mnotificationm Anager.notify (Id_3, Genrenotification (Mcontext, Icon_res, NOTIFYTEXT3, nOtifyTitle3, NOTIFYTEXT3, intent_3));
The visible ID and intent are different, and the generated pendingintent correspond to different intent. However, you will find that no matter which notification, pass back is the last notify intent. This is intent_3.
Looking for a long time, try to change pendingintent flag also no fruit, and finally in this post to find the answer (Csdn post), I come to summarize:
The problem is mainly in pendingintent.getactivity (), the second parameter of the API document, although the parameter is not used (the given example is also directly written 0), is actually through this parameter to distinguish between different intent, if the ID is the same, It will cover up the previous intent. So always get to the last intent.
As long as each different intent corresponds to pass a separate ID on it, the above function is modified as follows (add ID parameter):
Java code
- Private Notification genrenotification (context context, int icon, string tickertext, string title, string content, int ent intent, int id) {
- Notification Notification = new Notification (icon, Tickertext, System.currenttimemillis ());
- //The problem is here ID.
- Pendingintent pendintent = pendingintent.getactivity (context, ID, intent, pendingintent.flag_update_current);
- Notification.setlatesteventinfo (context, title, content, pendintent);
- Notification.flags |= Notification.flag_auto_cancel;
- return notification;
- }
- ...
- Mnotificationmanager.notify (Id_1,
- Genrenotification (Mcontext, Icon_res,
- NotifyText1, NotifyTitle1, NotifyText1, Intent_1, id_1));
- ...
- Mnotificationmanager.notify (Id_2,
- Genrenotification (Mcontext, Icon_res,
- NotifyText2, NotifyTitle2, NotifyText2, Intent_2, id_2));
- ...
- Mnotificationmanager.notify (Id_3,
- Genrenotification (Mcontext, Icon_res,
- NOTIFYTEXT3, NotifyTitle3, NotifyText3, Intent_3, id_3));
[Problem solving] pendingintent intent are overwritten when multiple notification are displayed?