Why my repeating alarm is triggered much rarer than expected?

90 Views Asked by At

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);
}
1

There are 1 best solutions below

3
tyczj On

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