-
Notifications
You must be signed in to change notification settings - Fork 194
How TrueTime works
It's pretty simple actually. We make a request to an NTP server that gives us the actual time. We then establish the delta between device uptime and uptime at the time of the network response. Each time "now" is requested subsequently, we account for that offset and return a corrected Date object.
Also, once we have this information it's valid until the next time you boot your device. This means if you enable the disk caching feature, after a single successful NTP request you can use the information on disk directly without ever making another network request. This applies even across application kills which can happen frequently if your users have a memory starved device.
If the device is booted, the information received as part of the previous NTP request is no longer valid.
We have a BootCompletedBroadcastReceiver
class that should automatically invalidate the cached information.
You will have to rerun the Truetime.init
call at regular/frequent intervals so you resynchronize with the true time. Have a look at this section for more details on the why and how.