Search code examples
androidalarmmanagerandroid-pendingintent

AlarmManager: shorter intervals for testing


I know that in production devices AlarmManager cannot be triggered more often than 1/minute. This is fine, but for testing I would like to have a short time.

 manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
    SystemClock.elapsedRealtime() - 10000, 60000, pendingIntent)

Is there some workaround? What is the recommended procedure to test?


Solution

  • Android devices will not trigger repeating alarms with intervals of less than about 1 to 2 minutes (some devices have more strict rules). If you want to have alarms triggered more often, you must use a single (non-repeating) alarm, use setExact() when possible, and then when the alarm goes off, you set the next one. In this way you can get much shorter intervals with more precise timing.