Android Development Intent.setflags () _ Let Android click on the notification bar information and return to the running program

Source: Internet
Author: User

Android Development Intent.setflags () _ Let Android click on the notification bar information and return to the running program 

Use the background service in the application, and push the message in the notification bar, hoping to click this message to return to activity,

The results always have several same activity, even if the activity being returned is in the foreground, the same activity will be reopened after clicking on the message, returning several times to exit.

And not like QQ, such as clicking the notification Bar message back to the previous activity, if there is no longer create a new activity

Said a bit around, if it is encountered this kind of problem certainly can understand, did not meet the estimate to understand my this chaotic expression ....

After reviewing the information, it is solved by the following way,

In fact, the main credit is the 10th line,

public void Shownotification (String msg) {Notificationmanager barmanager= (notific        Ationmanager) Getsystemservice (Context.notification_service); Notification notice = new Notification (Android.        R.drawable.stat_notify_chat, "The server sent a message", System.currenttimemillis ());        Notice.flags=notification.flag_auto_cancel;        Intent appintent = new Intent (intent.action_main);        Appintent.setaction (Intent.action_main);        Appintent.addcategory (Intent.category_launcher); Appintent.setcomponent (New ComponentName (This.getpackagename (), this.getpackagename () + "." + This.getlocalclassname         ())); Appintent.setflags (intent.flag_activity_new_task| intent.flag_activity_reset_task_if_needed);//Key step, set startup mode Pendingintent Contentintent =pendingintent.getactivity (        this, 0,appintent,0);        Notice.setlatesteventinfo (This, "notice", "Information:" +msg, contentintent);           Barmanager.notify (Status_bar_id,notice); }

Android Development Intent.setflags () _ Let Android click on the notification bar information and return to the running program

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.