alarmmanager - Android Alarm manager to run a task on a specific time -
i have read many articles, non seems work me!
i have schedule repeating task alarmmanager everyday @ 7:15. following method set in activity , registered broadcast receiver it!
private void settask(context context) { calendar updatetime = calendar.getinstance(); updatetime.settimezone(timezone.gettimezone("gmt")); updatetime.set(calendar.hour_of_day, 7); updatetime.set(calendar.minute, 15); intent intent = new intent(context, notifyupdate.class); pendingintent firealarm = pendingintent.getbroadcast(context, 0, intent, pendingintent.flag_update_current); alarmmanager alarms = (alarmmanager) getsystemservice(context.alarm_service); alarms.setrepeating(alarms.rtc_wakeup, updatetime.gettimeinmillis(), alarms.interval_day, firealarm); }
the problem when run app method gets executed regardless of time set, not executing @ (7:15).
any idea?
try before setting alarm
calendar = calendar.getinstance(); if (updatetime.before(now)) { updatetime.add(calendar.day_of_month, 1); // if in past increment } alarms.setrepeating(alarms.rtc_wakeup, updatetime.gettimeinmillis(), alarms.interval_day, firealarm);
you said have immediate triggering not depending on time. it's happening because updatetime-object references @ time in past, goal set alarm 7:15 in future. avoid immediate triggering.
Comments
Post a Comment