Skip to content Skip to sidebar Skip to footer

Why Does My Alarm Go Off Straight Away? (android)

Trying to set alarms for certain days of the week, but currently puzzled as to why this alarm is getting fired immediately, no matter what I pass in as hr and min... (I know the da

Solution 1:

If calendar calendar.before(Calendar.getInstance()) == true (it means your are setting alarm to start in the past, it will fire immediately.

In such situation you can do following:

long start = calendar.getTimeMillis();
if (calendar.before(Calender.getInstance()) {
     start += AlarmManager.INTERVAL_DAY * 7;
}
// set alarm with start time

From docs:

If the time occurs in the past, the alarm will be triggered immediately, with an alarm count depending on how far in the past the trigger time is relative to the repeat interval.

Post a Comment for "Why Does My Alarm Go Off Straight Away? (android)"