How to delete the old notification to show only one? #15051
Unanswered
ComptonAlvaro
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to use a service in a foreground service. This service, run a PeriodicTimer() that every 5 seconds notify with an event a text to the foreground service. Then the foreground service update the notification in the status bar.
The next that the service notify is a count with the number of times that it is execute the timer.
I can stop the foreground service and start again.
The problem is that when I stop the foregroud and start again, I can see the two notifications. One continues counting the first notificacion and the second starts to count from one.
So supose that I start the foreground and i let it goes until 10.
I stop the foreground.
I start the foreground again.
I see a first notification that shows 1 and after this, another notification with the value of 11.
So it seems that still exists the first notification, and when I update the notification with NotificationManager, it updates the two notifications.
I would like to have only one notification and Update it, not create a new notification each time the service notify to update the notification.
I am following this documenation:
The code of my foreground service class is this:
The Foreground Service:
The service with the timer:
In the foreground service, where I update the notification with NotificationManager.Notify(); I have tried to use StartForeground(NOTIFICATION_ID, notification) instead to use NotificationManager.
This works I expected, but I don't know what it does really. does it create a new foreground service? Does it just update the notification? Does it create a new notification and dispose the actual notification?. Really I don't know what this methods does.
Thanks so much.
Beta Was this translation helpful? Give feedback.
All reactions