Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通知取消问题_Android_Notifications - Fatal编程技术网

Android 通知取消问题

Android 通知取消问题,android,notifications,Android,Notifications,我想删除顶部栏中的所有通知。为此,我使用以下代码 notification = (NotificationManager) mContextNotification.getSystemService(NOTIFICATION_SERVICE); if(mNotificationManager != null) mNotificationManager.cancelAll(); 但没有从酒吧中删除通知。我的代码中有什么问题?您正在声明通知,但试图使用mNotificationManager

我想删除顶部栏中的所有通知。为此,我使用以下代码

notification = (NotificationManager) mContextNotification.getSystemService(NOTIFICATION_SERVICE);

if(mNotificationManager != null)
  mNotificationManager.cancelAll();

但没有从酒吧中删除通知。我的代码中有什么问题?

您正在声明
通知
,但试图使用
mNotificationManager

我个人在恢复应用程序时删除所有通知时没有遇到任何问题:

@Override
public void onResume() {
    super.onResume();
    mNotificationManager.cancelAll();
}

mNotificationManager被声明为与您的一样(只称为正确的东西)。如果您使用onCreate中的系统服务创建它,并在一段时间后对其执行取消操作,则它不应为null。

很抱歉在代码中键入错误。我现在已经改正了。但它不起作用