问题描述
- 清除一个通知状态出现的问题
-
我不知道如何清除一个通知状态。public void NotificationStatus(){ Intent intent = new Intent(this, Stimulation.class); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification( david.flanagan.android.VenAssist.Activities.R.drawable.notification_icon, "VenAssist Stimulation ON", System.currentTimeMillis()); PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0); notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.setLatestEventInfo(this, "VenAssist", "Stimulation Started", activity); notificationManager.notify(0, notification); }
我想在服务器的onDestroy()函数中通过调用
notification.cancel(0);
来清除通知状态。我创建了一个通知的实例,不确定对不对。
private NotificationManager notification;
我想取消服务时,因此清除 status bar,程序就崩溃了。
解决方案
加上第一句试试:
NotificationManager m_NotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
m_NotificationManager.cancel(0);
时间: 2024-09-10 14:42:00