返回首页
当前位置: 主页 > Import business >

Importandroid clear the notification bar message

时间:2012-01-28 10:01
  

> This project is coming near the end, the manager asked me to deal with a problem that we shut down the program, the program issued a notice in the status bar has not been eliminated, the need to manually clear, experience, and a very good, it is like in the program after the release of the notice to remove, and pondering the next, I do not know how clear, looked under the api a clear way, followed by more peace of mind, but troubles, and what I call the Notification Manager to notify the elimination of ah, he is open one by one in the service, we can not new in this class, is the system, when a decision to send a broadcast clear, when the program exits, call the broadcast the message clearly, the time until the quick finish, only to find, since is a system call, the system must have the end of the callback ah immediately thought of ondesory () method, because no matter how I quit the program, will be called and saved me a lot of effort, the code will line! write This just told myself, something in the application of the system, we should follow the rules of the game system, the time necessary to create the creation, where the release is necessary to release! seems to understand the life cycle of the system is not yet in place ah! following code fragment: view plainpackage com.liao.notification;importjava.util.arraylist;importandroid.app.activity;importandroid.app.notification; import android.app.notificationmanager; 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 notificationmanager notimanager; handler handler = new handler () {public void handlessage (message msg) {/ / todo auto-generated method stubif (msg.what == 1) {message = "type == == 1 ";} else if (msg.what == 2) {message =" type ==== 2 ";} notimanager = (notificationmanager) getsystservice (notification_service); notification notification = new notification (r.drawable.icon "You have new messages" + type, syst.currenttimillis ()); intent 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 = pendingintent.getactivity (getapplicationcontext (), 100, intent, pendingintent.flag_update_current); notification.setlatesteventinfo (getapplicationcontext (), type + "", message, pendingintent); notimanager.notify (0, notification );}};overridepublic void oncreate (bundle savedinstancestate) {super.oncreate (savedinstancestate); linearlayout layout = new linearlayout (this); button button = new button (this); button . settext ("Test notification1"); button.setonclicklistener (new onclicklistener () {public void onclick (view v) {type = 1; handler.sendptymessage (1 );}}); button button2 = new button (this); button2.settext ("Test notification2"); button2.setonclicklistener (new onclicklistener () {public void onclick (view v) {/ / handler.sendptymessage (2); / / type = 2; notimanager.cancel (0); / / call him on the line this time 0 and notimanager create incoming 0 is unique, so he can delete}}); layout.addview (button); layout.addview (button2); setcontentview (layout );}}>

------分隔线----------------------------
最新文章