Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset notificationmanager number on notification clear

What's the best way to clear the notification number when the user clicks on the notification? I say the best way, but really I haven't found ANY way. I'm launching a built in activity when the user clicks on the notification, not something I wrote so I can't clear it that way. I've got the notification manager's flag set to clear

   NotificationManager notification
    .
    .
    .
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.number++;
    nm.notify(1,notification);

But whatever I do the Notification.number keeps going up and never resets to 0.

like image 355
JonF Avatar asked Jul 05 '10 05:07

JonF


People also ask

How do I clear my ongoing notifications?

First, press-and-hold on the persistent notification you want to remove. Another option is to swipe the notification left or right, and then tap on the cogwheel icon shown next to it. Next, tap on the switch next to Permanent to disable it, and then press Save.

How do I clear all notifications on Android?

Use notifications To clear one notification, swipe it left or right. To clear all notifications, scroll to the bottom of your notifications and tap Clear all.

How do I make my notifications not dismissable?

Use the flag, FLAG_ONGOING_EVENT to make it persistent.

How do I use Notification Manager?

Notification Manager. Android allows to put notification into the titlebar of your application. The user can expand the notification bar and by selecting the notification the user can trigger another activity. Because notifications can be very annoying, the user can disable notifications for each application.


1 Answers

You could use an intermediary activity which is part of your app and thus can reset your variable and then start the internal activity.

So the chain would be

Notification --starts--> Intermediary Activity --starts--> Built-in activity

like image 78
Al Sutton Avatar answered Oct 05 '22 11:10

Al Sutton