安卓:自定义时钟部件服务变通? [英] Android: Custom Clock widget Service work-around?

查看:169
本文介绍了安卓:自定义时钟部件服务变通?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是开发一个时钟部件的主屏幕,并在阅读的主屏幕小工具教程的,我想知道如果有一个pre-现有的服务我可以引用用于更新当前时间,而不是重新发明轮子?

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?

我下载我的Andr​​oid手机的复古时钟的应用程序,并注意到,当我点击它,它会弹出闹钟设置,但默认的谷歌的模拟时钟的窗口小部件,在点击什么也不做。

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?

任何帮助是AP preciated。

Any help is appreciated.

我相信实现服务更新时钟会消耗电池寿命极大,在工作的任何想法左右或帮助了解任何性能问题,一些轻使用服务

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?

推荐答案

我的猜测:复古时钟部件响应触摸,和火灾关闭该启动闹钟设置页面的意图。你可以看在Android源$ C ​​$ C要弄清楚什么意图,这将是。要了解如何为您的小部件实际上火的意图,你可以看的在Android开发指南 code的例子。

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:

请注意:如果设备处于睡眠状态时,它是时间的更新(由updatePeriodMillis定义),那么该设备将依次执行更新醒来。如果不更新超过每小时一次,这可能不会造成对电池的寿命显著的问题。 然而,如果你需要更频繁地和/或不需要进行更新,而该设备是睡着了,然后就可以,而不是基于该不会唤醒设备的告警进行更新。更新到为此,请与您的AppWidgetProvider收到意向报警,使用AlarmManager。设置报警类型要么ELAPSED_REALTIME或RTC的,这将仅提供警报时,该设备是清醒的。然后设置updatePeriodMillis为零(0)。

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").

(从应用程序的窗口小部件指南


顺便说一句,我有机会与HTC Hero的发挥。我注意到,当你醒来从睡眠英雄,它模拟时钟插件的手开始在12。然后,它旋转手中各地去的适当的时间。这可能是因为他们不更新,而手机正在睡觉。

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.

这篇关于安卓:自定义时钟部件服务变通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆