Android Service.startForeground does NOT respect notification id uniqueness

谁说胖子不能爱 提交于 2019-12-18 16:55:41

问题


Service.startForeground() vs NotificationManager.notify(), give different behaviors.

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

When doing 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 (foreground) service that can have several (dynamic number) notifications?


回答1:


Well, it's not the best solution, but you can always just "reassign" a notification to a dismissed notification ID. For example, say you start Process 1 (foreground) and then Process 2 (using NotificationManager). When Process 1 ends, dismiss the notification for Process 2 and update the foreground notification for Process 1 to actually now show the progress for Process 2.

That way you don't have to call stopForeground() and startForeground(), which may allow the service to be killed in between (haven't actually checked that's true, though).



来源:https://stackoverflow.com/questions/9927938/android-service-startforeground-does-not-respect-notification-id-uniqueness

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!