Below is the code I am using to create alarms when data is pulled from external API. If the time set is in the past, the alarm goes off as soon as it is set(2 second gap). For e
This is the expected behavior.
From the documentation of setRepeating() (and other AlarmManager
set methods):
If the stated trigger time is in the past, the alarm will be triggered immediately
If you would like to prevent that happening, then simply do not set alarms with a past trigger time (e.g. check against System.currentTimeMillis()
when setting the alarm).