Android Service.startForeground DOES NOT respect the uniqueness of the notification identifier

Service.startForeground () vs NotificationManager.notify () , give different forms of behavior.

When using notify with two different notification identifiers, 2 notifications are created - Good .

When you do the same with startForground , one notification overrides the other - Bad .

Tested device: Nexus S (2.3.6) and Asus Transformer (4.0.3).

Any ideas how I can run an important (front) service that can have multiple (dynamic numbers) notifications?

+6
source share
1 answer

Well, this is not the best solution, but you can always simply β€œreassign” the notification to the rejected notification identifier. For example, let's say you run Process 1 (foreground) and then Process 2 (using NotificationManager). When process 1 ends, release the notification for process 2 and update the foreground notification for process 1 to actually show progress for process 2.

Thus, you do not need to call stopForeground() and startForeground() , which may allow you to kill the service between them (although this has not actually been verified).

0
source

Source: https://habr.com/ru/post/911950/


All Articles