Sergio Viudes
Sergio Viudes

Reputation: 2854

AlarmManager, repeating alarms and daylight saving

I scheduled an alarm, that triggers every day at the same hour. I set it as repeating alarm (using AlarmManager.setRepeating()) and it triggers every 24 * 60 * 60 * 1000 milliseconds (24 hours). I don't know if I must control daylight saving time changes, or it's automatic.

I tested this with:

  1. I changed mobile device time to one minute before daylight saving time change (1:59) (change is from 2 am to 3 am).
  2. I scheduled an alarm to 3:01.
  3. I waited 2 minutes, and the alarm fired OK.

But if I set this alarm that runs every day, for example, 2 days before daylight saving time change... It would run as expected after daylight saving time change? Or do I need to control it?

Upvotes: 1

Views: 1155

Answers (2)

JonasOliveira
JonasOliveira

Reputation: 704

You need to use TIME_TICK intent also. This intent is fired in each change of time on Android. Also by minors corrections automatically done by network.

Upvotes: 0

Dodge
Dodge

Reputation: 8307

you need to add a TIMEZONE_CHANGED receiver and reshedule your alarms (stop and restart)

<receiver android:name="RecevierTimeZoneChange">
  <intent-filter>
    <action android:name="android.intent.action.TIMEZONE_CHANGED"></action>
  </intent-filter>
</receiver>

Upvotes: 1

Related Questions