A
A
AnonovichAnon2017-03-19 16:44:13
Android
AnonovichAnon, 2017-03-19 16:44:13

Why doesn't the AlarmManager fire exactly after a given amount of time?

Why does the AlarmManager sometimes not execute exactly after 5 minutes , as it should? It may, for example, sometimes not work - but in the next period of time as many as 2 (or 3) times, or it lags behind by 1 minute with a frequency of half an hour. In general, some misunderstandings with its operation on a real device.
API 17 if anything (Android 4.2.1 which). Those. setRepeating should return the exact interval.

public void scheduleAlarm()
{
    Intent intent = new Intent(getApplicationContext(), TestAlarmReceiver.class);
    final PendingIntent pIntent = PendingIntent.getBroadcast(this, TestAlarmReceiver.REQUEST_CODE,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    long firstMillis = System.currentTimeMillis();
    AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis, 5 * 60 * 1000, pIntent); // каждые 5 минут

    Log.i(TAG_LOG, "The alarm started");
}

Logs:
<...>
03/17/2017
07:20:30 03/17/2017
07:25:30 03/17/2017 07:30:30 03/17/2017 07:40:25 <-
here
03/17/2017 07:40:30 <- 03/17/2017
07:45:30
03/17/2017 07:50:30 03/17/2017 07:55:30
03/17/2017 08:00:30
03/17/2017
08:10:25 <-here 03/17/2017
08:10 :30 <
-here 03/17/2017
08:15:30 03/17/2017 08:20:30
<...>
03/17/2017 16:50:30
03/17/2017 16:55:30
03/17/2017 17:01:10 <
-here 17.03.2017 17:05:30 17.03.2017
17:10:30
17.03.2017 17:15:30
17.03.2017 17:21:08 <
-here 17.03.2017 17:25:30
17.03.2017 17 :40:29 <
-here 3/17/2017 5:40:29 pm <-here
03/17/2017 05:40:30 PM <- here
03/17/2017 05:45:30
03/17/2017 05:51:09 PM < - here
03/17/2017 05:55:30 03/17/2017
06:00:50 PM
<... >

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question