Android系统。报警管理大火奇怪的时代 [英] Android. Alarm Manager fires in strange times

查看:155
本文介绍了Android系统。报警管理大火奇怪的时代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code设置重复报警(每5分钟)。

I used the following code to set repeating alarm (every 5 minutes).

public void SetAlarm(Context context)
{
     AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
     Intent i = new Intent(context, Alarm.class);
     PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
     am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 5, pi); // Millisec * Second * Minute
 }

时似乎工作正常(它运行近20小时),并在服务器上,我可以看到一些不变邮件到达。

Is seems to work fine (it runs almost 20 hours), and in the server I can see that some constant message arrives.

然而,也有一些是关于时间: 我想时间是每隔五分钟,这似乎是在服务器中我接收不同时间的消息。

However, there is something about the times: I want the times to be every five minutes, and it seems like in the server I receives the messages in different times.

我加当服务器收到的消息,当手机处于睡眠模式时的第一序列(在夜间):

I add a first sequence of times when the server received messages, when the phone was in sleep mode (in the night):

05:13:51,
05:18:54,
05:24:54,
05:28:54,
05:33:51,
05:38:54,
05:52:45,
05:54:54,
05:58:52,
06:04:54,
06:08:54,
06:16:19,
06:18:54,
06:24:54,
06:28:54,
06:34:54,
06:48:42,
06:48:44,
06:58:54,

当我使用的手机不时另一个序列:

And another sequence when I used the phone from time to time:

11:08:46,
11:13:45,
11:18:48,
11:23:52,
11:33:54,
11:38:47,
11:48:47,
11:58:47,
12:03:52,
12:08:45,
12:14:49,
12:18:43,
12:25:37,
12:28:41,
12:34:56,
12:38:47,
12:43:48,
12:48:56,
12:54:07,
12:58:48,
13:03:43,
13:08:56,
13:14:11,
13:18:55,
13:25:02,
13:28:45,
13:33:43,
13:44:57,
13:48:58,
13:54:57,
13:58:52,
14:03:58

我注意到三个不同的异常:

I notice to three different anomalies:

  1. 跳过报警器(用于服务器中的两个消息在10分钟至例如间隔) - 它似乎没什么问题,而且可能是由于连接问题

  1. Skipping over alarm (for example interval of 10 minutes between two messages in the server) - it seems fine to me, and might be due to connectivity problems.

的两个消息,并接4分钟之间6分钟模式。你可以看到这种模式比一次多。我有一个假设,即操作系统做了一些优化,例如,如果有其他报警每两分钟(对于是否有新的电子邮件例子检查),它运行在一起(和无线电是只打开一次,而不是二)。

Pattern of 6 minutes between two messages, and then 4 minutes. You can see this pattern more than one time. I have an assumption, that the OS does some optimization, and if for example it has other alarms every two minutes (for example checking if there are new emails), it runs them together (and the radio is turn on only one time instead of two).

奇怪的时间间隔(我无法解释它们) - 你可以看到

Strange intervals (I can't explain them) - you can see.

所以我的问题:

  1. 我怎么能强制系统完全运行每5分钟(或更努力)?

  1. How can I enforce the system to run exactly every 5 minutes (or to try harder)?

什么原因奇怪的时机?我写了我的想法,但这些都只是想法。

What are the reasons for the strange timing? I wrote what I think, but these are only thoughts.

谢谢!

推荐答案

从API(这里):

注:与API 19(奇巧)警报传递开始是不准确的:操作系统   会以最小化唤醒和电池使用Shift报警。那里   一些新的API来支持它需​​要严格的交付应用程序   担保;看到setWindow(INT,很长很长,PendingIntent)和   setExact(INT,长,PendingIntent)。应用其   targetSdkVersion早于19 API将继续看到   previous行为中,所有警报什么时候交付   请求。

Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

因此​​,如果您使用的是API 19,然后回答您的两个问题...

So, if you are using API 19, then answers to your two questions...

这篇关于Android系统。报警管理大火奇怪的时代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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