1

I have simply functional for start service and repeat he:

mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);

PendingIntent pIntent = PendingIntent.getService(mContext,
                SendStatusService.SEND_STATUS_SERVICE_CODE,
                mIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + 2000,
                mIntervalInMs,
                pIntent);

I understand the documentation: alarm manager regardless of device state (sleep or not) start service through 2000 ms and repeat with interval mIntervalInMs.

But service start working after 30-50 sec after running this code. What i make wrong or no understand the documentation?

abbath0767
  • 946
  • 2
  • 11
  • 31

1 Answers1

1

setRepeating() is "inexact" with a targetSdkVersion of 19 or higher when running on an API Level 19+ Android device. Hence, your results are not surprising. The events will occur somewhere around the desired time (until Android 6.0's Doze mode kicks in), but they will not occur exactly at the desired time.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • hm. i have flag ACTION_IGNORE_BATTERY_OPTIMIZATION and his permission in settings (app for only me. i know what is bad=)). How then works another app with clock-alarm? They awaken the user (and smartphone) at a certain time, not a minute earlier nor later. – abbath0767 Jul 04 '17 at 07:07
  • @abbath0767: "How then works another app with clock-alarm?" -- alarm clock apps will use `setAlarmClock()` on `AlarmManager`. See [this answer](https://stackoverflow.com/a/34699710/115145) for more. – CommonsWare Jul 04 '17 at 11:11