如何更新Android小工具每一秒......画有秒针的时钟?秒针、时钟、小工具、每一秒

2023-09-06 23:23:32 作者:相关比较有意境的>>

我已经从各种来源读太多的方式来更新正在使用ImageView的画布小部件,并绘制方法来显示与秒针的时钟。

I have been reading much from various sources on ways to update a widget that is using ImageView Canvas and Draw method to display a clock with a seconds hand.

必须每秒更新一次。什么是最有效的方式做到这一点?使用服务,报警管理,处理程序?

It must be updated every second. What is the most efficient way to do this? Use a Service, the Alarm Manager, Handlers?

这是可以做到,比如,Android应用弧时钟小工具。

It can be done, e.g., the Android app "Arc Clock Widget".

与任何人任何想法?

谢谢,汤姆

推荐答案

有此页:)的的教程上作出模拟时钟部件的Andr​​oid

我已经使用了AlarmManager这个做我自己,我没有发现任何显著电池消耗的AlarmManager不会唤醒手机更新widget时手机是睡着了。不管怎么说,没有人会看到widget时手机是睡着了。此外,请参阅在Android开发者指南的这一部分这一点。 使用AlarmManager频繁更新

I have used the AlarmManager to do this myself and I did not notice any significant battery drain as the AlarmManager does not wake the phone to update the widget when the phone is asleep. Anyways, no one will be seeing the widget when the phone is asleep. Also, see this note on this section of the Android Developer Guide. Using AlarmManager to update frequently