This is almost the end of the project. The manager asked me to solve a problem, that is, after our program is closed, the notification sent by the program has never been cleared on the status bar and needs to be clarified manually,
The experience is extremely poor. Now I want to eliminate the notification after the program is launched. I have thought about it. I don't know how to understand it. I have read the methods for clearing the API, so I feel more at ease later.
But something went wrong. I called the notification manager to eliminate the notifications. He started one service one by one. We couldn't use the new class. It was a system. At that time, I thought about it.
I decided to send the broadcast clearly. When the program exited, I called the broadcast to clear the message. When the program was finished, I found that, since the broadcast was called by the system, there must be an end callback.
I immediately thought of the ondesory () method, because my program will call this method no matter how it exits, and it saves me a lot of effort and the code is just a line!
I just want to tell myself that we should follow the rules of the system in the application system to create a game, and the place where the game is released will be released!
It seems that the system's life cycle is not very well understood!
After talking so much nonsense, I also pasted the test code and wrote it casually.
Package COM. liao. notification; import Java. util. arraylist; import android. app. activity; import android. app. notification; import android. app. icationicationmanager; import android. app. pendingintent; import android. content. intent; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. util. base64; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. linearlayout; import android. widget. textview; public class mainactivity extends activity {private int type; private string message; private icationicationmanager notimanager; handler = new handler () {public void handlemessage (Message MSG) {// todo auto-generated method stubif (MSG. what = 1) {message = "type = 1";} else if (MSG. what = 2) {message = "type = 2";} notimanager = (icationicationmanager) getsystemservice (icationication_service); Notification = new notification (R. drawable. icon, "you have new message" + type, system. currenttimemillis (); intent = new intent (); intent. setclass (getapplicationcontext (), reciveactivity. class); intent. putextra ("hello", "Hello dialog"); intent. setflags (intent. flag_activity_clear_top | intent. flag_activity_new_task); pendingintent = pendingintent. getactivity (getapplicationcontext (), 100, intent, pendingintent. flag_update_current); notification. setlatesteventinfo (getapplicationcontext (), Type + "", message, pendingintent); notimanager. Y (0, notification) ;}}; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); linearlayout layout = new linearlayout (this); button = new button (this); button. settext ("test icationication1"); button. setonclicklistener (New onclicklistener () {public void onclick (view v) {type = 1; handler. sendemptymessage (1) ;}}); button button2 = new button (this); button2.settext ("test icationication2"); button2.setonclicklistener (New onclicklistener () {public void onclick (view V) {// handler. sendemptymessage (2); // type = 2; notimanager. cancel (0); // call it. The value 0 is unique when notimanager is created, so you can delete it according to him.}); layout. addview (button); layout. addview (button2); setcontentview (layout );}}