6

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.

JonF
  • 2,336
  • 6
  • 38
  • 57

2 Answers2

2

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

Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
Al Sutton
  • 3,904
  • 1
  • 22
  • 17
  • 4
    It would not need to be an intermediary activity. The `Notification` could have a `PendingIntent` for a broadcast `Intent`, picked up by a `BroadcastReceiver`, that clears the `Notification` and calls `startActivity()` on the other activity. That way, there would be no UI hiccup. But, an activity (or conceivably service) could work as well. – CommonsWare Jul 05 '10 at 11:11
  • So I could set up a broadcast receiver only to clear the notification count? I thought you could only modify notifications from your own activity? – JonF Jul 07 '10 at 02:50
0

I am using a combination of what @CommonsWare recommends and extending an application object as here How to update notification number .

Edit: Further testing shows that actually this is not working because the BroadcastReceiver is called on every notification and because it reset the number on every notification the number is never correct.

Community
  • 1
  • 1
Eugene van der Merwe
  • 4,390
  • 1
  • 35
  • 48