[英]Android : Stopping works Widget when user removes app from recent tasks list
I have a Timer in my app widget. 我的app小部件中有一个Timer。 This timer will be updating the Widget UI every second.
此计时器将每秒更新Widget UI。 All the process works perfectly.
所有过程都完美无缺。 But, when user removes my app from recently apps task list, timer stops immediately.
但是,当用户从最近的应用任务列表中删除我的应用时,计时器会立即停止。
Anybody knows how to fix this problem? 有谁知道如何解决这个问题?
Put your logic for controlling the Widget
in a Service
. 将您的逻辑用于控制
Service
的Widget
。 in onStartCommand()
method, start a time scheduler thing, or register for ACTION_TIME_TICK
which will send an event, every minute. 在
onStartCommand()
方法中,启动时间调度程序,或者每分钟注册一次将发送事件的ACTION_TIME_TICK
。
Also remember to return START_STICKY
from your Service
so that the OS can restart the service in cases where your process gets closed by the OS itself or by swiping away from recent task list. 还要记住从
Service
返回START_STICKY
,以便操作系统可以在操作系统本身关闭进程或从最近的任务列表中滑动时重新启动服务。
One caveat is that restarting the service after swiping from recents would not happen in KitKat Android duo to a bug. 需要注意的是,在KitKat Android duo中发生错误后,重新启动服务不会发生。 Though there's a dirty workaround for it.
虽然有一个肮脏的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.