我注意到一个奇怪的东西与Android的报警 - 它们并不总是在正确的时间间隔唤醒设备。举例来说,如果我设置闹钟启动服务,每5分钟(使用RTC_WAKEUP或类似),一切工作正常,直到设备进入睡眠状态 - 在这之后,警报可能不会火分钟,或接近一个小时。它通常会触发最终 - 它始终闪光,如果我唤醒设备由pressing菜单。使用重复警报(相对于每一次重新设置它们)具有相同的效果。
I'm noticing a strange thing with Alarms on Android - they don't always wake up the device at the correct intervals. For example, if I set an alarm to start a service every 5 minutes (using RTC_WAKEUP, or similar), everything works fine until the device goes to sleep - after that, the alarm may not fire for minutes, or close to an hour. It usually does fire eventually - and it always fires if I wake the device by pressing Menu. Using repeating alarms (vs. re-setting them each time) has the same effect.
所以我的问题是,报警保证火在适当的时间间隔时,该设备是睡着了吗?我知道我不应该期望分钟毫秒或第二precision,不过几十?
So my question is, are alarms guaranteed to fire at proper intervals when the device is asleep? I understand that I shouldn't expect millisecond or second precision, but tens of minutes?
推荐答案我从来没有编程,在Android上,但我是有点无聊,所以我用Google搜索四周,发现这一点,这似乎是非常相关的:groups.google/group/android-developers/browse%5Fthread/thread/f0303a539de3a74a (您需要登录到您的谷歌帐户,以便阅读)
I've never programmed on Android but I was kinda bored so I googled around and found this, which seems to be very related: groups.google/group/android-developers/browse%5Fthread/thread/f0303a539de3a74a (you'll need to sign in to your google account in order to read it)
我再看看AlarmManager 文档和我注意到它 有关使用警报器,只会谈 广播事件,无法启动服务。 我改变周围的事物用 BroadcastReceiver的而不是 在它的onReceive获取锁() 和存储在锁引用作为 另一个类的静态成员, 下面的例子 AlarmClock的应用程序: android.git.kernel/?p =平台/封装/应用程序/ AlarmClock.gi ...
I had another look at the AlarmManager documentation and I noticed that it only talks about using alarms to broadcast events, not start services. I changed things around to use a BroadcastReceiver instead that acquires the lock in its onReceive() and stored the lock reference as a static member of another class, following the example of the AlarmClock application: android.git.kernel/?p=platform/packages/apps/AlarmClock.gi...
这似乎已经奏效。我猜 发生了什么事是,我的服务 启动报警人被解雇,但 将该装置有时要回 睡觉之前,我可以收购之后 锁。显然,只有保证 在收到报警时,即发 的是,的onReceive将运行到 完成。
That seems to have worked. I guess what was happening was that my service starting alarms were being fired, but the device was sometimes going back to sleep before I could acquire the wake lock. Apparently the only guarantee that is made when an alarm is received is that the onReceive will run to completion.
我想我要的情况下,发布此 人是不断寻找相同 问题。
I just thought I'd post this in case anyone is ever searching for the same problem.
更多推荐
在谷歌Android报警
发布评论