Skip to content Skip to sidebar Skip to footer

How Can I Invoke The Alarm For The Past Time Using Alarm Manager In Android?

i am using alarm manager to invoke the alarm. here i am trying to invoke alarm for the past time means i gave time 10am at i am 11am. The alarm invoke instantly. But i need to invo

Solution 1:

 Date dat  = new Date();//initializes to now
Calendar cal_alarm = Calendar.getInstance();
Calendar cal_now = Calendar.getInstance();
cal_now.setTime(dat);
cal_alarm.setTime(dat);
cal_alarm.set(Calendar.HOUR_OF_DAY,5);//set the alarm time
cal_alarm.set(Calendar.MINUTE, 59);
cal_alarm.set(Calendar.SECOND,0);
if(cal_alarm.before(cal_now)){//if its in the past increment
    cal_alarm.add(Calendar.DATE,1);
}
//SET YOUR AlarmManager here

this will solve your problem in this we compare now time with set time , this ll add one date in your alarm manager

Solution 2:

You need to invoke it in 23 hours... Not in -1 hours. Past time alarms are invoked instantly

Post a Comment for "How Can I Invoke The Alarm For The Past Time Using Alarm Manager In Android?"