0

I am designing an alarm clock app, and I need to listen to two system broadcasts: Intent.ACTION_TIME_CHANGED and Intent.ACTION_DATE_CHANGED.

I believe ACTION_TIME_CHANGED is fired when the user manually changes the time. But when is ACTION_DATE_CHANGED broadcasted?

The documentation of this action is not quite convincing. It says,

The date has changed.

Who changed the date? The user, by changing the date setting? Or did the clock tick over to the next day?

Two Stack Overflow answers that I found regarding this:

  • Answer 1: The broadcast is fired when the clock ticks over to the next day.
  • Answer 2: The broadcast is fired when the user manually changes the date, and is not automatically triggered by the system.

The two answers indicate completely different behaviour. If answer #1 is correct, I will listen to this broadcast using a context-registered receiver. If answer #2 is correct, I need to register a context-registered receiver for Intent.ACTION_TIME_TICK and then manually check whether we are in the next day or the same day.

Wrichik Basu
  • 1,005
  • 17
  • 28

1 Answers1

0

As per the suggestion by @Nicolas, I tested both the broadcasts. The results:

  • ACTION_TIME_CHANGED is broadcasted only when the user manually changes the date, time or time format (from 12-hour to 24-hour format or vice-versa).

  • ACTION_DATE_CHANGED is broadcasted only when the day changes, i.e. when we go from 11:59 PM to 12:00 AM of the next day. This is automatically triggered by the system.

Wrichik Basu
  • 1,005
  • 17
  • 28
  • One thing to note that now these broadcast may or may not fire when system in DOZE mode. :) – Hitesh Chavda Nov 28 '20 at 05:54
  • Not only that, [another SO question](https://stackoverflow.com/q/16684132/8387076) has pointed out that if the device has "Use network provided date and time" enabled, then `ACTION_TIME_CHANGED` and `ACTION_TIMEZONE_CHANGED` may be fired even when the user has not manually changed the date and/or time. – Wrichik Basu Nov 28 '20 at 16:50
  • There is a bug regarding `ACTION_DATE_CHANGED` so it does not always fire up when clock goes from 23:59 to 00:00, nor does it always fire when you change the date manually. It is not reliable at all. [link](https://stackoverflow.com/questions/21758246/android-action-date-changed-broadcast/21980389) – Torima Apr 15 '22 at 12:11