StanislavOssovsky
StanislavOssovsky

Reputation: 37

Why my repeating alarm is triggered much rarer than expected?

I am writing my first alarm program. The program sets a repeating alarm, which is expected to trigger every 200mseconds. But the point is, instead of that, the interval is almost 40 seconds!! And it seems that whatever interval time I set it doesn't really matter. So in reality it seems that after API 19 there is no way to make setRepeating() kind of an alarm to trigger more often, than ~40 seconds, right? Here is a snippet of the code:

if(alarmRepetition.equalsIgnoreCase(context.getString(R.string.alarm_once))){
      Intent backIntent = new Intent("Time to delete an Alarm kva-kva");
      backIntent.putExtra("Time to delete", alarmId);
      Calendar calendarNow = Calendar.getInstance();
      PendingIntent pendingIntent = PendingIntent.getBroadcast(context, alarmId, backIntent, 0);
      AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      alarmManager.setRepeating(AlarmManager.RTC, calendarNow.getTimeInMillis(), 200, pendingIntent);
}

Upvotes: 0

Views: 117

Answers (1)

tyczj
tyczj

Reputation: 73856

As per the docs

as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time as described above

AlarmManager will try to schedule alarms together to save battery life

Upvotes: 2

Related Questions