Android Question Clock widget killed by Android

Paulo Rosa

Licensed User
Hi all,

I build a clock widget which uses a Broadcast Receiver to capture "android.intent.action.TIME_TICK". So, every minute my widget displays the current time.

Also, when I touch the time label of the widget, it opens the standard Android Clock app, so I can see the alarms, chronometer and other clock functions.

My phone runs Android 7.0.

The Service_Start Sub of the widget service module has these lines of code at its end:


Despite of that, the widget service is eventually killed by the system. That happens in only one combination of situations: when I go to sleep at night and kept the phone unattended for several hours AND the phone is kept online. In other words, whenever I go to bed at night and forgot to set the phone to airplane mode, my clock widget is completely dead by the morning. The widget's time display is frozen at a time about 2 hours after I slept. The click action (which was supposed to open the standard Android Clock app) does nothing.

My clock app is included on my phone battery optimization white list, i.e., the Android 7.0 battery optimization shouldn't affect my clock widget.

But, when I go to bed AND set my phone to airplane, my clock widget is never killed. That's weird!