In my app I’m using a GPS listener. I need to turn off the GPS and activate it later. Currently I’m using
locationManager.removeUpdates(locationListener);
to turn off the gps. That will turn the GPS off. But later I’m not able to turn it on? Is there any other methods to turn off the gps?
For activating the GPS I’m using
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updatesInterval, 0, locationListener);
I want the gps to return the most accurate value. So I set the minValue and minDistance value of the requestLocationUpdates function to 0.
Then to solve the problem with battery drain I’ll start and stop the gps (which is a service) when the app comes to foreground and when the app enters background.
To start the GPS i used
in the onCreate of the service.
To end the GPS i used
in the onDestroy of the service.
You have to do the starting and stopping of the gps in a service, so that you can start and stop the same instances of the location listener otherwise this thing will go drastically wrong