• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Timing in requestLocationUpdate() and in handler.postDelayed()

ac4android

Well-Known Member
In each instance, I specified 15 seconds, like this:
Code:
LocationManager.GPS_PROVIDER ,15000 , 10 , locationlistener(){ ...;}
//...lines elided ...
handler.postDelayed(this, 15000);
...
I then captured 230 readings in a table and noticed that the intervals varied widely, from as little as 7 seconds and not once on 15 seconds.

Is this normal?

How accurate are the timings?

It's not good.
 
Well according to the reference documentation for requestLocationUpdates(), the elapsed time between updates shouldn't be less than minTime, and if the change in location is less than minDistance, you won't get an update (in your case 10 metres).
So I'm surprised you're getting updates in 7 seconds. How are you measuring the time difference?

https://developer.android.com/refer....html#requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener)
 
The documentation is not clear on which parameter takes precedence.

Does minTime takes precedence over minDistance or vice versa e.g. if I cover 10 meters in less than 15 seconds, will I get an update?

I use the database time from the stock standard ANSI-SQL current_timestamp when I upload via http the location data to a MySQL table. It will have not more than 1-2 seconds latency.

But I can see from Toast message that the interval between 2 consecutive updates is less than the minTime.

ADDENDUM:
  • the requestLocationUpdate() is in the foreground thread i.e. the UI thread. The foreground activity is in itself a "Looper", hence my LocationListener in this thread;
  • the updates and displays are handled by a 2nd thread, created by Handler;
  • the actual upload to database is in an AsyncTask inside the second thread, hence handler.postDelayed();

ADDENDUM (from documentation)
If it is greater than 0 then the location provider will only send your application an update when the location has changed by at least minDistance meters, AND at least minTime milliseconds have passed.
 
Last edited:
OK, a slight re-arrangement of the codes sees a consistent elapsed time => minTime.

Coukld have bee the interaction between minTime for requestLocationUpdates() and postDelayed(). Wish I have timeOnHand() to find out :)
 
Back
Top Bottom