Android: Custom Clock widget Service work-around?

落爺英雄遲暮 提交于 2019-12-06 12:03:16

My guess: the Retro Clock widget responds to touches, and fires off the intent that launches the alarm clock setting page. You could look in the Android source code to figure out what intent that would be. To see how to wire up your widget to actually fire the intent, you can look at the code example in the Android dev guide.


For a clock widget, it seems like you have two requirements. It needs to update at least once per minute, but it doesn't need to update while the device is asleep. Here's a quote I found:

Note: If the device is asleep when it is time for an update (as defined by updatePeriodMillis), then the device will wake up in order to perform the update. If you don't update more than once per hour, this probably won't cause significant problems for the battery life. If, however, you need to update more frequently and/or you do not need to update while the device is asleep, then you can instead perform updates based on an alarm that will not wake the device. To do so, set an alarm with an Intent that your AppWidgetProvider receives, using the AlarmManager. Set the alarm type to either ELAPSED_REALTIME or RTC, which will only deliver the alarm when the device is awake. Then set updatePeriodMillis to zero ("0").

(from the App Widgets guide)


Incidentally, I got a chance to play with an HTC Hero. I noticed that, when you wake a Hero from sleep, the hands on its analog clock widget start at 12. Then, it spins the hands around to get to the proper time. This is probably because they don't update it while the phone is sleeping.

Check this out. It implements the clock with a service, and it subscribe to the screen-off event so that it will suspend the service while screen is off to save some battery.

The reason it pops up the alarm clock is because it has implemented the OnClick method and from there it launches the alarm clock. You can launch any activity from the OnClick, in a lot of cases widgets use that to launch their own configuration utility.

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