Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android foreground service notification replace

if I start a service with startForeground(myID, not), can I replace the not for another one without stopping the foreground process? I mean, I have a service that will do two task in a row before service ends, and I want to notify user when the first ends without the need to stop foreground Service?

Also, is it possible to start a foreground service with no notification (i.e. NULL).

any stretegy I can use instead of? thanks.

like image 563
Tibor Avatar asked May 30 '26 16:05

Tibor


1 Answers

The general answer to your question is to use the NotificationManager.notify() method using the same id passed into the startForground() method when starting the service.

Also worth noting :

  • Updating the notification will NOT remove the service's foreground status.
  • You cannot cancel the notification using the NotificationManager.notify. Instead you must call stopForeground() which removes the service's foreground status as well.

Refer to the answer given by Luca and the discussion under CommonsWare's answer, as well as the answers given in by Lorne Laliberte and dmmh.

How do I update the notification text for a foreground service in Android?

Does updating a Notification remove a Service's foreground status?

like image 70
TheIT Avatar answered Jun 02 '26 20:06

TheIT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!