在谷歌Android报警

编程入门 行业动态 更新时间:2024-10-09 23:12:12
本文介绍了在谷歌Android报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我注意到一个奇怪的东西与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的而不是   在它的onR​​eceive获取锁()   和存储在锁引用作为   另一个类的静态成员,   下面的例子   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报警

本文发布于:2023-11-27 11:02:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!