android - How to sync AlarmManager with system time? -


i have question, i'm using alarmanager update widget every minute (it's clock) display current time, however, alarmmanager never synced system clock in device, use this:

alarmmanager.setrepeating(alarmmanager.rtc, system.getcurrenttimeinmillis(), 60000, pendingintent); 

it works every minute, however, problem that, if put widget in screen @ 2:15:30 pm example, 1 minute after time alarmmanager going call broadcast again, next update @ 2:16:30 pm, , won't synced system time because when system time displays 2:16:00pm widget still show 2:15:00pm.

i hope clear enough, appreciate help, thank you.

the second argument setrepeating time want alarm fire first time. need arithmetic align next minute boundary. example like:

 = system.getcurrenttimeinmillis();  oneminutefromnow =  + oneminute;  nextminuterollover = oneminutefromnow - (oneminutefromnow % oneminute); 

then use nextminuterollover second argument setrepeating.

(this simplified -- made verbose see code doing.)


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -