问题
I'm building an alarm clock app in Android. Does AlarmManager automatically handle clock changes between summertime and wintertime or do I need to manage that explicitly?
edit: If an alarm is set where the repeat interval crosses a clock change will that alarm need to be rescheduled?
回答1:
AlarmManager
will take care of the day light saving. It reset the Timezone info at the beginning of each day taking daylight saving info into consideration.
回答2:
As opposed to what the accepted answer says I saw a different behavior in my app, I have a task running daily a few minutes after midnight.
After a daylight saving time change, the task started running a few minutes after 11:00PM causing the task to return wrong results (the task checks the current date and queries stuff accordingly).
So my answer is - yes, you'll need to manage that explicitly.
EDIT: our task needed to run once a day at a specified time.
To solve this issue, we save the last time our app ran, and check that timestamp whenever the task runs again.
If the timestamp is not 24h (might be 23h or 25h because of DST change), we abort the AlarmManager
and schedule a new one instead.
So we have up to 2 "missed" runs a year (we can live with that).
来源:https://stackoverflow.com/questions/8377853/does-android-alarmmanager-handle-daylight-saving-changes