dev_android
dev_android

Reputation: 8818

Notification cancel problem

I want to delete all the notification that are present in the top bar. For that I use the following code.

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

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

But no notification is deleting from the bar. What is the problem in my code?

Upvotes: 1

Views: 1846

Answers (1)

Codemonkey
Codemonkey

Reputation: 3412

You are declaring notification but trying to use mNotificationManager?

I personally had no trouble removing all notifications when my app is resumed:

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

The mNotificationManager is declared like yours (only called the correct thing). It should never be null if you create it with the system service in onCreate like that and do the cancel on it some time later.

Upvotes: 2

Related Questions