How to update an Android widget every second … to draw a clock with a seconds hand?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 00:52:04

问题


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?

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

Anyone with any ideas?

Thanks, Tom


回答1:


There are several solutions discussed on this page :) A Tutorial on Making an Analog Clock Widget for Android

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



来源:https://stackoverflow.com/questions/3486243/how-to-update-an-android-widget-every-second-to-draw-a-clock-with-a-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!