在我的应用程序中,我运行了几个服务.当用户停止应用程序(UI部分)服务仍在后台运行并且状态栏中显示通知(每个服务有一个)时.单击它时出现对话框,选择取消适当的服务.
这是我的问题.出现问题时,应用程序崩溃通知仍保留在状态栏区域中.是否可以在显示标准的android force关闭对话框之前清除所有通知?
当我尝试打开活动点击通知时,真正的错误是NPE.这是固定的.但我只想知道在应用程序崩溃时如何清除所有内容.
这是我最后的解决方案,受到老鼠帖子的启发.在创建方法的应用程序中我注册了Thread.setDefaultUncaughtExceptionHandler()
@Override
public void onCreate() {
super.onCreate();
this.notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
UncaughtExceptionHandler appHandler = new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
this.notificationManager.cancelAll();
defaultHandler.uncaughtException(thread, ex);
}
};
Thread.setDefaultUncaughtExceptionHandler(appHandler);
}
谢谢