简体   繁体   English

Android:当用户从最近的任务列表中删除应用程序时,停止工作小工具

[英]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 . 将您的逻辑用于控制ServiceWidget 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.

相关问题 当应用程序从android中的最新应用程序列表中删除时,服务停止 - Service stopped when the app removes from recent apps list in android 当用户从最近的应用程序列表中删除应用程序时,如何取消警报管理器警报? - How to cancel alarm manager alarms when user removes the app from recent apps list? 活动会从最近的应用列表中删除该应用 - An Activity removes the app from recent apps list 从最近的任务中删除应用程序时,Android 通知被取消 - Android notification gets cancelled when app is removed from recent tasks 用户从android中的后台删除应用程序时如何检测事件? - How to detect event when user removes app from background in android? 当用户从“最近使用的应用程序”列表中滑动Android应用程序时会发生什么? - What happens when the user swipes an Android App from the Recent Apps List? 将应用添加到Android中的最新任务列表(长按主屏幕按钮) - Adding app to recent tasks list in Android (long press home button) 从Android的“最近列表”中删除应用程序后,如何触发事件 - How to trigger an event, when app is removed from Recent List in Android 当应用程序从 android 的最近列表中删除时,会调用哪个活动? - Which activity is called when app removed from recent list in android? 从KITKAT的最新应用列表中清除后,Android警报将被取消 - Android alarm is cancelled when cleared from recent app list in KITKAT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM