I am building application which is time sensitive i.e. some tasks need to be completed within certain time. There are multiple ways to get the time i.e. System.currentTimeMillis()
and gpsLocation.getTime()
. I don't want to use System.currentTimeMillis()
because user can manually change the time. What about gpsLocation.getTime()
? I have observed that in some areas, device is unable to get GPS
location. Which timestamp
should I use then?
Location Timestamp
open fun onLocationChanged(location: Location?) {
ellapsedTime = location.getTime()
}
I am detecting whether user has changed the Auto Time and Timezone settings with the following code:
val isAutoTime = Settings.Global.getInt(activity!!.getContentResolver(), Settings.Global.AUTO_TIME)
val isAutoTimezone = Settings.Global.getInt(activity!!.getContentResolver(), Settings.Global.AUTO_TIME_ZONE)
What approach should I use to get the timestamps?
What is missing in question?
Please comment what is the missing part? Or it may be the case that you are not understanding the question/concern. I am writing for best approach to compare the timestamps. I have added pros and cons of using System.currentTimeinMillis()
and location.getTime()
. As application is time dependant so if user plays around with time settings then I should be able to compare accurate timestamps rather than system time.