[英]How to continuously update notification even when app is not running?
I am trying to implement a timer with notification that cannot be swiped away by user. 我正在尝试实现一个带有通知的计时器,该通知不能被用户抹去。 I want to continuously update the timer's time. 我想不断更新计时器的时间。
I know there are a lot of similar question online. 我知道在线上有很多类似的问题。 But a lot of them discuss using handler, or a service. 但是许多人讨论使用处理程序或服务。 All of these won't run when my app is not being used by the user. 当用户不使用我的应用程序时,所有这些都将无法运行。 AlarmManager doesn't work because i want to update every x millisecond. AlarmManager不起作用,因为我想每隔x毫秒更新一次。
Thanks. 谢谢。
Use a foreground service 使用前台服务
A foreground service performs some operation that is noticeable to the user. 前台服务执行一些用户注意的操作。 For example, an audio app would use a foreground service to play an audio track. 例如,音频应用程序将使用前台服务来播放音轨。 Foreground services must display a Notification. 前台服务必须显示通知。 Foreground services continue running even when the user isn't interacting with the app. 即使用户未与应用程序进行交互,前景服务也将继续运行。
There is a limit on how frequently you can update the notifications as well, every MS will cause problems. 您还可以多长时间更新一次通知,每个MS都会引起问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.