简体   繁体   中英

Android : Stopping works Widget when user removes app from recent tasks list

I have a Timer in my app widget. This timer will be updating the Widget UI every second. 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 . in onStartCommand() method, start a time scheduler thing, or register for ACTION_TIME_TICK which will send an event, every minute.

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.

One caveat is that restarting the service after swiping from recents would not happen in KitKat Android duo to a bug. Though there's a dirty workaround for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM