i am using alarm manager to invoke the alarm. here i am trying to invoke alarm for the past time me开发者_开发技巧ans i gave time 10am at i am 11am. The alarm invoke instantly. But i need to invoke it next day 10am. Please provide a way to invoke alarm for the next day or past time.
Please suggest me
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
You need to invoke it in 23 hours... Not in -1 hours. Past time alarms are invoked instantly
精彩评论