Android notifies PendingIntent of the intention to open the Activity, and the data is not updated? Solution

Source: Internet
Author: User

When Notification is used, the PendingIntent delay intent is used to open the Activity and display the Notification details. If multiple notifications come, but the Intent and so on are the same, but the content of the notification is different, the data displayed for the Notification Details Activity opened multiple times is actually the first data, the data is not updated. For example, display the code: www.2cto.com [java] // the app's own notification pops up, And the SMS result of xx reply is displayed in the notification bar private void popNotification (Context context, SmsMsg smsMsg) {String body = smsMsg. getBody (); String promptContent = null; if (null! = Body & body. length ()> 10) {promptContent = body. substring (0, 10);} else {promptContent = body;} CharSequence charDateTime = DateFormat. format ("yyyy-MM-dd kk: mm: ss", new Date (smsMsg. getTime (); // obtain icationicationmanager nm = (icationicationmanager) context. getSystemService (Context. NOTIFICATION_SERVICE); // create a Notification object Notification n = new Notification (R. drawable. ic_launcher, "Xx SMS reminder", System. currentTimeMillis (); n. flags = Notification. FLAG_AUTO_CANCEL; // after the notification is clicked, it will automatically disappear n. defaults | = Notification. DEFAULT_SOUND; // default music n when the notification arrives. defaults | = Notification. DEFAULT_VIBRATE; // The default vibration Intent readMsgIntent = new Intent (context, SmsReadActivity. class); readMsgIntent. putExtra ("SmsMsg", smsMsg); // send the received SMS to readMsgIntent in the activity. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); // In the service To enable an Activity, you need to put this tag // PendingIntent. FLAG_UPDATE_CURRENT. When intent carries different data, the activity can get different data. PendingIntent pi = PendingIntent. getActivity (context, 300, readMsgIntent, 0); // The activity n specified by readMsgIntent is enabled after the user clicks. setLatestEventInfo (context, "xx SMS reminder" + charDateTime, promptContent, pi); nm. running y (10, n);} the error code is: PendingIntent pi = PendingIntent. getActivity (context, 300, readMsgIntent, 0); change 0 to PendingIntent. change FLAG_UPDATE_CURRENT to PendingIntent pi = PendingIntent. getActivity (context, 300, readMsgIntent, PendingIntent. FLAG_UPDATE_CURRENT); // the activity specified by readMsgIntent is enabled after the user clicks. the following describes how to use FLAG_UPDATE_CURRENT using the API: Flag for use with getActivity, getBroadcast, andgetService: if the described PendingIntent already ex, then keep it but its replace its extra data with what is in this new Intent. this can be used if you are creating intents where only the extras change, and don't care that any entities that were ed your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.

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.