Android:自定义时钟小部件服务解决方法?
我对为主屏幕开发时钟小部件感兴趣,并在阅读 主屏幕小部件教程,我想知道是否有一个预先存在的服务
我可以参考来更新当前时间而不是重新发明轮子?
我在 Android 手机上下载了复古时钟应用程序,并注意到当我单击它时,它会弹出闹钟设置,但使用默认的 Google 模拟时钟小部件,单击不执行任何操作。
这是因为 Retro Clock 小部件实现了闹钟服务吗?如果是这样,我该如何引用该服务?还是我这一切都错了并且被误解了?
任何帮助表示赞赏。
编辑:
我相信实施更新时钟的服务会极大地消耗电池寿命,有什么解决办法的想法或有助于阐明使用 Service
的任何性能问题吗?
I was interested in developing a clock widget for the homescreen and upon reading Home Screen Widgets tutorial, I wondered if there is a pre-existing Service
I could reference for updating the current time rather than re-inventing the wheel?
I download the Retro Clock application on my android phone and noticed that when I click it, it pops up the Alarm Clock settings, but with the default Google Analog Clock widget, upon click does nothing.
Is that because the Retro Clock widget implements the Alarm Clock service? If so, how can I go about referencing that service? Or do I have this all wrong and misunderstood?
Any help is appreciated.
EDIT:
I believe implementing the service to update the clock would drain the battery life tremendously, any ideas on a work around or help shed some light on any performance issues with using Service
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的猜测:复古时钟小部件响应触摸,并触发启动闹钟设置页面的意图。您可以查看 Android 源代码以了解其意图。要了解如何连接您的小部件以实际触发意图,您可以查看 Android 开发指南中的代码示例。
对于时钟小部件,您似乎有两个要求。它需要至少每分钟更新一次,但不需要在设备睡眠时更新。这是我找到的一句话:
(来自应用程序小部件指南)
顺便说一句,我得到了一个有机会与 HTC Hero 一起玩。我注意到,当您将英雄从睡眠中唤醒时,其模拟时钟小部件上的指针会从 12 点开始。然后,它会旋转指针以达到正确的时间。这可能是因为他们在手机休眠时不会更新。
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:
(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.
它弹出闹钟的原因是因为它实现了 OnClick 方法,并从那里启动闹钟。您可以从 OnClick 启动任何活动,在很多情况下,小部件使用它来启动自己的配置实用程序。
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.