3

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?

Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
SBotirov
  • 13,872
  • 7
  • 59
  • 81

1 Answers1

1

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.

Ashkan Sarlak
  • 7,124
  • 6
  • 39
  • 51
  • I don't think it's a bug. See the answer here: http://stackoverflow.com/a/6299862/2511775 The `BroadcastReceiver` object gets cleaned up pretty quickly. And `AppWidgetProvider` is a child of `BroadcastReceiver`. – Ashkan Sarlak Sep 07 '15 at 06:28
  • @Sarlak I tired your idea but not working, I return START_STICKY but OS not restarted Service – SBotirov Sep 07 '15 at 11:45