简体   繁体   English

如果屏幕关闭,如何更新时钟小部件?

[英]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. 我使用了本教程http://forum.xda-developers.com/showthread.php?t=1732939创建一个简单的时钟小部件。

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 https://developer.android.com/training/scheduling/alarms.html

Or at "WakeLock": 或在“ 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. 使用唤醒锁的一种合理情况可能是后台服务,该服务需要获取唤醒锁以在屏幕关闭时保持CPU正常运行。 Again, though, this practice should be minimized because of its impact on battery life. 同样,这种做法应尽量减少,因为它会影响电池寿命。

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

Using the first approach can help you to get your point. 使用第一种方法可以帮助您理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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