在我的应用程序中,我使用一个服务,当它运行时,它会在通知栏中显示一个图标。通知创建如下:
private void showNotification() {
Notification notification = new Notification(R.drawable.ic_action_video, "Nachricht 1", System.currentTimeMillis());
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, VIRAPRecorderActivity.class), 0);
notification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.recorder_running),
intent);
// user cannot dismiss notification
notification.flags = Notification.FLAG_ONGOING_EVENT;
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(12345, notification);
}
在我的服务的onDestroy()方法中,我尝试取消通知,如下所示:
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(12345);
这不起作用。尽管应用已关闭,但通知仍然可见。为什么?怎么解决?
答案 0 :(得分:0)
如果您关闭应用程序,服务将不会停止。您必须明确停止服务,然后才会调用服务的onDestroy()
。