简体   繁体   中英

How to update clock widget if screen is turned off?

I used this tutorial http://forum.xda-developers.com/showthread.php?t=1732939 to create a simple clock widget.

Sadly it's not running very well. When the screen is turned off, the widget won't update anymore so it won't show the corret time.

So, how can I update the widget even if the screen if turned off?

Take a look at Repeating Alarms:

They operate outside of your application, so you can use them to trigger events or actions even when your app is not running, and even if the device itself is asleep.

https://developer.android.com/training/scheduling/alarms.html

Or at "WakeLock":

One legitimate case for using a wake lock might be a background service that needs to grab a wake lock to keep the CPU running to do work while the screen is off. Again, though, this practice should be minimized because of its impact on battery life.

https://developer.android.com/training/scheduling/wakelock.html#cpu

Using the first approach can help you to get your point.

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