For the convenience of novice, although very simple, but I see no one in the park to write ... So just ... (I am also a novice ~)
is actually using the activity stack principle ....
Written in Mainactivity's Oncreat ():
Notificationmanager Notificationmanager =(Notificationmanager) Getsystemservice (Context.notification_service); Notification Notification=NewNotification (R.drawable.ic_launcher,"hello,there!", System.currenttimemillis ()); Notification.flags=Notification.flag_auto_cancel;
Intent Intent=NewIntent ( This, Notworkactivity.class);//NOTICE HERE!!!
Intent.setflags (Intent.flag_activity_clear_top|intent.flag_activity_new_task); Pendingintent contentintent= Pendingintent.getactivity ( This, R.string. App_name, Intent, pendingintent.flag_update_current); Notification.setlatesteventinfo ( This,"hello,there!","Hello,there,i ' m John.", contentintent); Notificationmanager.notify (0, notification);
This will generate a notification each time the program starts;
Note that the Notworkactivity code ~ ~ is as follows:
protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); // just a word!! this . Finish (); }
Each time a stack is retired, the top of the stack becomes the last activity.
And then the other activity doesn't have to worry about anything,
Android:launchmode= "Singletask"
will be able to run properly ~ ~
Welcome veteran has a better way ...
When using notification in Android, click the Home button and return to the activity before clicking the Home button from the notification options.