Android Question Questions about DateTime.ListenToExternalTimeChanges

corwin42

Expert
Licensed User
Longtime User
With DateTime.ListenToExternalTimeChanges we can update the system time for the B4A process if it is changed externally.

As I am currently working on the WatchFace library this is very important to WatchFaces. In the Android Studio example code Google adds a dynamic Receiver to receive this event, too.

In my B4A Watchface Service I just put DateTime.ListenToExternalTimeChanges into the Service_Create sub. This seems to work. The time in the watchface gets updated if I update the time in the settings of the watch.

The difference to the code of the Android Studio Example is that they disable the receiver if the watchface gets invisible and reenable it, when the watchface gets visible again and they always update the local time/timezone in this case.

My question: There is no "manual" way in B4A to update the local time but only the above method call.
Isn't it possible that the Service gets killed by the Android system (if another app is in the foreground) but the process keeps running while the system time is changed, too? In this case, if the user returns to the watchface the service will be started again but I guess that the process will miss the time change event and so the watch will show a wrong time.

Or will the active receiver prevent the service from being killed by the system? I'm just wondering why they disable the receiver when the WatchFace gets invisible.
 
Top