I\'m supposed to update the listener every 5 seconds. But it doesn\'t. What could be wrong with my code?
Thanks a lot for any help!
package com.example.a
By setting it to 5000 ms it doesn't necessarily mean that you will get the location every 5th second. The time is more or less a best case scenario.
minTime the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value. http://developer.android.com/reference/android/location/LocationManager.html
Are you sure you have your activity running? If you want to recieve the location when the activity is sleeping you need a wake lock and a service.
For example in a GPS app I created I put 0 ms to get it as soon as possible but when debugging and checking the logcat I sometimes get the location every minute or so, not every second.
As stated by David Olsson, MINIMUM_TIME_BETWEEN_UPDATES
only prevents the listener to be requested too often. If you want to regularly requestLocationUpdates
, you should use Timer
and TimerTask
and have requestLocationUpdates
run once every 5 seconds
schedule(TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.