'Once I posted a notification message, is there a way to remove it or replace it?
I am working on a mobile app for Android. The app generates quite a lot of notifications, but they all have expiration tag on them. So, say, I don't want to display what was 2 hours ago if something, about the same subject, happened 1 hour ago.
Is there a way I can either
- replace a posted message
- or delete it in favor of a newer one?
Solution 1:[1]
You can use the Notifications Overview guide to see examples for various common notification use cases. The Notification updates and groups section has a couple of approaches that are relevant to your problem.
The simplest solution is to use the same ID in order to update the notification. As noted in the docs (quoted below), this will meet both your requirements.
To update this notification after you've issued it, call NotificationManagerCompat.notify() again, passing it a notification with the same ID you used previously. If the previous notification has been dismissed, a new notification is created instead.
You can optionally call setOnlyAlertOnce() so your notification interupts the user (with sound, vibration, or visual clues) only the first time the notification appears and not for later updates.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shriakhilc |
