java - How to cancel notification in onDestroy function -


I want to make a notification like BBM connected information (for android) ... so when I open my app , The notification will appear, and it can not be canceled ... then I use this code

  nm = (NotificationManager) getSystemService (context.NOTIFICATION_SERVICE); Notification Notification = New Notification (Android.Radrowerable.stat_notef_adm, "This is Important", System.contentime millis ()); Notification.flags = Notice. FLAG_NO_CLEAR; // Notification is missing any reference reference = main activity this; Charasata title = "Hello there"; Extreme Extension = "This is Demo"; Intent = intent (intent, main activity category); Pending pending = pending content Gate activity (context, 0, intent, 0); Notification.Setlat EventInfo (context, title, extension, pending); Nm.notify (0, notification);   

I had put that code in the public void on the crate (bundled saved instance) ... so, when I can not cancel the notification on click or slide, Close, I still have an idea of ​​using this code:

  @Override Safe void onDestroy () {nm.cancelAll (); }   

But, never called this function ???

How can I cancel the notice when I close the app?

This can be done because the onstore will not be called immediately when navigating with the Home button.

Android's callback methods are available, it works well with notifications and more. These are the on user lewhit () and onUserInteraction () .

Junkadak for Onuser Levhant () says:

The activity is called as a part of the life cycle when the result of a user's choice The background is going to the background. For example, when user presses the Home key, user lewant () will be called, but when an incoming call call in-call activity is automatically brought to the foreground, then the Universe Levehant () The activity will not be called on. In those cases when it is implemented, this method is called immediately before the on-pause (callback) of the activity.

The purpose of this callback and on-user interaction () is to help the activities to be repeatedly run in the notifications; Especially, to assist in the activities in determining the appropriate time to cancel the information.

I thought that you want to override any one of these; Especially the user Lev Hunt () seems a good choice for your purpose.

  @override protected user zero () {nm.cancelAll (); super.onUserLeaveHint (); }   

You can not stop the process of closing the application process. Android does not support this when the user does this, the system calls and all the resources will be free. It is not possible to catch this incident and to act before actually killing the process. Perhaps an alternative is possible, but it will not be what Android wants.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -