views:

39

answers:

1

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.

+1  A: 

You could used 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

Al Sutton
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
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