intent updateintent = new Intent (Getnoticeservice.this, Detailgonggaoactivity.class); Updateintent.putextra ("type", "Weidu"); Updateintent.putextra ("title", (String) Json.get ("title")); Updateintent.putextra ("id", Json.get ("Noticeid"). toString ());// Add this sentence will not appear the same activity occurred multiple times updateintent.addflags (intent.flag_activity_clear_top);//The following parameters, is the key to set pendingintent Updatependingintent = Pendingintent.getactivity (Getnoticeservice.this, I, UpdateIntent, Pendingintent.flag_update_current); Notification updatenotification = new Notification ();//Set the notification bar to display the contents Updatenotification.icon = R.drawable.logo; Updatenotification.flags |= updatenotification.flag_auto_cancel;updatenotification.tickertext = "The field Wizard sent a new announcement notice"; Updatenotification.defaults = notification.default_sound;//ringtone Alert Updatenotification.setlatesteventinfo ( Getnoticeservice.this, "The field Elf sent a new announcement notice", (String) json.get ("title"), Updatependingintent); Updatenotificationmanager.notify (i, updatenotification);
Add this sentence will not appear the same activity occurred multiple times, do not explain updateintent.addflags (intent.flag_activity_clear_top);
Updatenotificationmanager.notify (i, updatenotification); This sentence passed I marked the location of updatenotification and the ID of the same time to overwrite the original updatenotification, so to pass a different ID, so that the different updatenotification do not overwrite.
Pendingintent updatependingintent = pendingintent.getactivity (Getnoticeservice.this, I, UpdateIntent, Pendingintent.flag_update_current); Notification updatenotification = new Notification ();
Flags have four values:
int flag_cancel_current: If the pendingintent already exists, the current is canceled before the new is generated.
int flag_no_create: If the pendingintent does not exist, return null directly instead of creating a pendingintent.
int Flag_one_shot: The pendingintent can only be used once, and is automatically canceled after the Send () method executes.
int flag_update_current: If the pendingintent already exists, the current data is updated with the newly-passed intent.
We need to change the last parameter to Pendingintent.flag_update_current, so that in the activated activity we can receive the data from the receiving intent normally.
The previous ID works the same
Android Pendingintent use notifications to pass multiple parameters and do not overwrite issues