Android的Service.startForeground不尊重通知ID唯一性 [英] Android Service.startForeground does NOT respect notification id uniqueness
问题描述
<一个href="http://developer.android.com/reference/android/app/Service.html#startForeground%28int,%20android.app.Notification%29">Service.startForeground() VS <一href="http://developer.android.com/reference/android/app/NotificationManager.html#notify%28int,%20android.app.Notification%29">NotificationManager.notify(),给不同的行为。
Service.startForeground() vs NotificationManager.notify(), give different behaviors.
在使用的通知有两个不同的通知IDS,创建2的通知 - 好
When using notify with two different notification ids, 2 notifications are created - Good.
在与做同样的 startForground ,一个通知将覆盖其他 - 坏
When doing the same with startForground, one notification overrides the other - Bad.
测试设备:歌Nexus S(2.3.6)和华硕变压器(4.0.3)
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?
推荐答案
嗯,这不是最好的解决办法,但你可以始终只是重新分配的通知被解雇的通知ID。例如,假设你开始处理1(前景),然后处理2(使用NotificationManager)。当处理完,驳回通知过程2和更新的前景通知流程1实际上现在显示的进程2的进展情况。
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.
这样,你不必叫 stopForeground()
和 startForeground()
,这可能使服务之间(还没有真正确认这是真的,虽然)被杀害
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).
这篇关于Android的Service.startForeground不尊重通知ID唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!