You should not call the gpsStart() method on a timer. I'm going to say how the Listening List works
What is a location receiver?
Location Listener is a class that notifies you when your current location is changed. To receive location updates, you will need to register the LocationListener class using the LocationManager class.
When to register a location receiver?
It depends on the requirements of your application. For example, if you want the location manager to display the current location on the map, you need to register the location receiver in the onCreate() or onResume() method of activity and unregister the recipient in the onPause() or onStop() method. If you want to get the location, even if your application is not running, you can use the service to get the location.
How to register / unregister a location receiver?
To register a LocationListener, you first need an instance of the LocationManager class, which you can get using a context, for example
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
After that, you will need to install a location provider. There are two types of providers that are often used.
- GPS Provider
- Network provider
Now, to register a location receiver with this location provider, there is a requestLocationUpdates LocationManager method. In this method, the first argument is the second argument to the provider β this is the minimum time to update the location of the request. The third argument is the minimum distance for a location change request. The biggest argument is for locationListener. Here, how you can use the method
locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, minTime, minDistance, locationListener); locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, minTime, minDistance, locationListener);
In order not to update location updates, you can use the method below.
locationManager.removeUpdates(locationListener)
Note. . You call the gpsStart method on a timer, as you mentioned in your question, so that it adds a location receiver every time this method calls. So all the listeners launch you a new place, so you probably get the same location several times. Instead, you should call this method once when your activity begins, and unRegister this locationListener when your activity ends.
Hope you get it .: D
Enjoy !!!