简体   繁体   English

如何每天更新主屏幕小部件

[英]how update home screen widget every day

I want to make my home screen widget updates once every day (at 24:00). 我想让我的主屏幕小部件每天更新​​一次(24:00)。 Should I use a service, or is there another way? 我应该使用服务,还是有其他方式?

I want to conserve battery charge. 我想节省电池电量。

You can set the update interval in WidgetProviderInfo to one day, but then you have no influence on the time the update is running. 您可以将WidgetProviderInfo中的更新间隔设置为一天,但是您不会影响更新的运行时间。

Easiest way is to set the update interval to every hour and read in onUpdate the current time. 最简单的方法是将更新间隔设置为每小时,然后读入onUpdate当前时间。 You ensure this way that your process runs at least between 0 and 1 am. 您可以通过这种方式确保您的流程至少在凌晨0点到凌晨1点之间运行。

A Service makes sence if your process runs long and should therefore stay away from the UI Thread. 如果您的流程运行时很长,那么服务就会发生,因此应远离UI线程。

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

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