当应用程序被系统杀死时如何删除通知?
How to remove notification when application is killed by the system?
我正在开发一个 Android 应用程序,当数据从我的一项活动上传到互联网时,它会通知用户。当用户通过我实现的菜单关闭应用程序时,我执行代码以删除我放置的通知:
notificationManager.cancelAll();
问题是用户可以通过多任务菜单终止我的应用程序(更可能的退出方式)并且代码没有执行。
我认为通过 onDestroy 方法可以解决我的问题:
@Override
public void onDestroy()
{
super.onDestroy();
notificationManager.cancelAll();
}
但是,似乎每次从多任务菜单退出应用程序时都不会调用此方法。
有没有办法在系统终止我的进程之前删除我的通知?
谢谢!
不幸的是,我认为不存在更好的处理方法。系统 应该 调用方法 onDestroy(),但您不能保证它确实如此。
There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it.
我正在开发一个 Android 应用程序,当数据从我的一项活动上传到互联网时,它会通知用户。当用户通过我实现的菜单关闭应用程序时,我执行代码以删除我放置的通知:
notificationManager.cancelAll();
问题是用户可以通过多任务菜单终止我的应用程序(更可能的退出方式)并且代码没有执行。
我认为通过 onDestroy 方法可以解决我的问题:
@Override
public void onDestroy()
{
super.onDestroy();
notificationManager.cancelAll();
}
但是,似乎每次从多任务菜单退出应用程序时都不会调用此方法。
有没有办法在系统终止我的进程之前删除我的通知?
谢谢!
不幸的是,我认为不存在更好的处理方法。系统 应该 调用方法 onDestroy(),但您不能保证它确实如此。
There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it.