1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Using DateTime.ListenToExternalTimeChanges

Discussion in 'Android Questions' started by dbprogramer, May 4, 2019.

  1. dbprogramer

    dbprogramer Member Licensed 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.
  2. Erel

    Erel Administrator Staff Member Licensed User


    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice