Android Question Using DateTime.ListenToExternalTimeChanges

dbprogramer

Member
Licensed User
Longtime User
I can't find any examples of how to actually use this feature. My app gives a daily reminder at the time set by the user then it sets the time for the next reminder (24 hours later). But if there is a time change, (DST or time zone change) then I can't figure out a way for my app to know that before the scheduled time and then it might be off one or more hours off. Where do I use DateTime.ListenToExternalTimeChanges -- does this continue to listen even if the program is not running? Do I put it in a service module that starts at reboot? (I found this brief example but I can't figure out how to make this work if my program is not currently running when the time changes -- https://www.b4x.com/android/forum/t...value-on-androidthings-app.75072/#post-476634) Once a time change would trigger then I assume I need to check current time and recalculate how much time until the reminder/notification is supposed to happen. Thanks for your help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
does this continue to listen even if the program is not running?
No.

You need to do two things:
1. Call DateTime.ListenToExternalTimeChanges in Service_Create of the starter service.
2. Create a static intent filter that listens to this action: "android.intent.action.TIMEZONE_CHANGED" (don't use the starter service for this).

The intent filter will cause your app to start when the time zone changes.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…