android - how to set repeating time in setExact() function of alarm manager -


everyone here saying use setexact api level 19 , higher couldn't find how set repeating time in repeated again @ specified time.

so please tell me how set repeating time in setexact method?

here code

 calendar calendar2,calendar,cal,cal2;         calendar = new gregoriancalendar();         calendar2 = new gregoriancalendar();          calendar2.settimeinmillis(system.currenttimemillis());         calendar.settimeinmillis(system.currenttimemillis());           cal = new gregoriancalendar();         cal2 = new gregoriancalendar();         cal.add(calendar.day_of_year, calendar.get(calendar.day_of_year));         cal.set(calendar.hour_of_day, 10);         cal.set(calendar.minute, 0);         cal.set(calendar.second, calendar.get(calendar.second));         cal.set(calendar.millisecond, calendar.get(calendar.millisecond));         cal.set(calendar.date, calendar.get(calendar.date));         cal.set(calendar.month, calendar.get(calendar.month));             alarmmanager alarmmanager = (alarmmanager)getsystemservice(alarm_service);         intent = new intent(mainactivity.this,start_service_alarm.class);          it.putextra(start_service_alarm.action, start_service_alarm.action);         pendingintent pendingintent = pendingintent.getbroadcast(mainactivity.this, 987654321, it, 0);         if(android.os.build.version.sdk_int<19)         {         alarmmanager.setrepeating(alarmmanager.rtc_wakeup, cal.gettimeinmillis(), alarmmanager.interval_day, pendingintent);         }else         {                alarmmanager.setexact(alarmmanager.rtc_wakeup, cal.gettimeinmillis(), pendingintent);          }             cal2.add(calendar.day_of_year, calendar2.get(calendar.day_of_year));         cal2.set(calendar.hour_of_day, 20);         cal2.set(calendar.minute, 0);         cal2.set(calendar.second, calendar2.get(calendar.second));         cal2.set(calendar.millisecond, calendar2.get(calendar.millisecond));         cal2.set(calendar.date, calendar2.get(calendar.date));         cal2.set(calendar.month, calendar2.get(calendar.month));           alarmmanager alarmmanager2 = (alarmmanager)getsystemservice(alarm_service);         intent itintent = new intent(mainactivity.this,stop_service_alarm.class);          itintent.putextra("action_stop", stop_service_alarm.action_stop);         pendingintent pendingintent2 = pendingintent.getbroadcast(mainactivity.this, 123456789, itintent, 0);         if(android.os.build.version.sdk_int<19)         {         alarmmanager2.setrepeating(alarmmanager.rtc_wakeup, cal2.gettimeinmillis(), alarmmanager.interval_day, pendingintent2);         }else          {             alarmmanager2.setexact(alarmmanager.rtc_wakeup, cal2.gettimeinmillis(), pendingintent2);         } 

unfortunately, scheduled times repeating inexact , read inexact full interval!

if targetsdkversion 19 or higher, yes.

what can instead set exact repeating alarm?

use setexact() control initial delay. then, part of work processing event, use setexact() control @ next desired time. iow, "repeating" part yourself.

yes, irritating.

it intentionally irritating, steer developers not use exact repeating alarms, worse battery inexact brethren. if user perceive inexact behavior , not appreciate it, feel free use setexact() make alarms occur when user wants. however, if user not perceive inexact behavior, please use inexact alarms, user may notice battery impact of exact alarms.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -