每 20-30 秒更新一次 Android 小部件的最佳方法:处理程序、服务还是警报?
我有一个 4x4 小部件,我想每 15-20 秒更新一小部分。显然我不希望在手机处于待机状态时更新它。除了我的计时器之外,小部件还需要响应一些系统事件。那么,哪个是最好的选择?
- AlarmManager:不错,但如果需要每 20 秒运行一次,可能会占用大量 CPU 处理
- 程序:很轻,但我不知道如何在手机休眠时停止它
- 服务:这里我还需要了解如何在手机休眠时停止它
我会还需要更新我的小部件的一小部分而不更新其所有屏幕区域,这可能吗?
谢谢大家。
I have a 4x4 widget and i want to update a little piece of it every 15-20 seconds. Clearly i don't want it to be updated when the phone is in standby. The widget needs also to respond to some system events other than my timer. So, which is the best option?
- An AlarmManager: nice but probably cpu intensive if it needs to be run every 20 seconds
- An Handler: light but i dont know how to stop it when phone sleeps
- A service: also here i need to understand how to stop it when phone sleeps
I will also need to update a little part of my widget without updating all its screen area, is this possible??
Thanks everybody.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请将此设置为可选或可配置。
Handler
与应用程序小部件无关。始终运行的服务对业务不利 并且是导致用户用任务杀手攻击你的事情。
最好的坏选择是
AlarmManager
。坦率地说,最好的答案是“不要每 15-20 秒更新一小部分”。
Please make this optional or configurable.
A
Handler
has nothing to do with app widgets.An always-running service is bad for business and is the sort of thing that causes users to attack you with task killers.
The best of the bad options is
AlarmManager
.Frankly, the best answer is "don't update a little piece of it every 15-20 seconds".