Android Pendingintent use notifications to pass multiple parameters and do not overwrite issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.