1

Note: Somewhere is StackOverflow have some answers to this question. but which is not helped me and the answers are not correct in my case. here are the links to those questions.

I am encountered one issue with Android's alarm manager. I am scheduling a repeating notification on DST enabled area. Here are my timezone settings

  • Region: Canada
  • TimeZone: Vancouver
  • Device: S9+ Android 10
  • DST Starts on - March 8 & DST ends on - Nov-1

I scheduled a notification on February 29 at 9:00 AM notification comes successfully, but after DST Starts on March 9th the notification fired at 10:00 AM. after DST ends it is back to normal. I need to fire the notification at exactly 9:00 AM every day independent of DST. Is this behavior is normal? there are no issues with iOS devices.

  • Is this is a bug from the Android side?
  • How to schedule the notification independent of DST?

Can anyone help me?

Here is my code to schedule the notification

Note: I have added the AlarmManager.RTC_WAKEUP as the alarm type and scheduled the interval as AlarmManager.INTERVAL_DAY. also, passed the UTC time to the alarm manager from the calendars calendar.getTimeInMillis() method.

alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, AlarmReceiver.class);
    alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 9);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, alarmIntent);

Test Procedure:

Setting the Region: Canada & TimeZone: Vancouver

  1. Schedule a repeating notification on Feb 15th at 9:00 AM
  2. Test whether the notification fired on Feb 16th at 9:00 AM -> Success, notification fired at 9:00 AM
  3. change the system time to March 9th (Which is on DST); observing the notification fires at 9:00 AM -> Failed, it fired on 10:00 AM
  4. Change the date to Nov 2nd (DST Ended) ; observing the notification fires at 9:00AM -> Success notification fired at 9:00 AM
  • No, I have done the exact same thing in my code also. – Akhil T Mohan Dec 31 '20 at 05:59
  • You should provide details about your test procedure. Also have you read: [AlarmManager: how to schedule a daily alarm and deal with time changes](https://stackoverflow.com/q/19421616/295004) – Morrison Chang Dec 31 '20 at 06:31
  • I added the test procedure. The Link you suggested will not solve my problem! Because in theory, it will work but on my real-time testing experience with AlarmManager it is not taking care of DST. Also, I Followed google's official doc to schedule the alarm. https://developer.android.com/training/scheduling/alarms#devsite-article#examples-of-real-time-clock-alarms – Akhil T Mohan Dec 31 '20 at 08:14

0 Answers0