Does Android AlarmManager handle daylight saving c

2019-03-31 12:27发布

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?

2条回答
Emotional °昔
2楼-- · 2019-03-31 12:35

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).

查看更多
来,给爷笑一个
3楼-- · 2019-03-31 12:51

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.

查看更多
登录 后发表回答