Does Android AlarmManager handle daylight saving changes?

房东的猫 提交于 2020-01-12 09:13:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!