Intent. setFlags () _ in android development. Let Android click the notification bar to return the running program.

Source: Internet
Author: User

The Background Service is used in the application and the message is pushed in the notification bar. You want to click this message to return to the activity,

There are always several identical activities in the result. Even if the returned activity is in the foreground, clicking the message will re-open the same activity and return several times to exit,

Instead of returning a click notification message like qq to an existing activity

It is a bit difficult to say. If you encounter such problems, you will certainly understand them. If you have never encountered such problems, you may not be able to understand this chaotic expression .....

After reading the information, we solved the problem through the following methods,

In fact, the main credit is 10th rows,

Public void shownotification (String msg) {icationicationmanager barmanager = (icationicationmanager) getSystemService (Context. NOTIFICATION_SERVICE); Notification notice = new Notification (android. r. drawable. stat_policy_chat, "the server sent the 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); // set the start mode to PendingIntent contentIntent = PendingIntent. getActivity (this, 0, appIntent, 0); notice. setLatestEventInfo (this, "notification", "information:" + msg, contentIntent); barmanager. Y (STATUS_BAR_ID, notice );}

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.