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