1

I develop app, which in service get location and send it to server. Service in background get location every 5 min(for example). Battery quickly dies, when GPS and Wi-Fi uses.. So, how can I save battery life ?

Thanks for help in advance!

Small question: Am I right to do request location updates every 5min code below? And is it correctly use requestLocationUpdates with NETWORK_PROVIDER and next with GPS_PROVIDER ? That necessary, when GPS not find signal, but Wi-Fi find signal and give coordinates. I do this:

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30000, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, locationListener);
researcher
  • 1,758
  • 22
  • 25

1 Answers1

1

First of all, you do have to realize that these functions that you need to use are probably one of the most demanding in terms of power. I've compiled a few things that might help you consume less power:

First of all see if you really need the accuracy GPS_PROVIDER. If not choose NETWORK_PROVIDER.

From what I see you set the requestLocationUpdates callback method to be called 2 times, by setting the NETWORK_PROVIDER and the GPS_PROVIDER. You do not need to use them both. Plus take a look at the parameters that you pass on the requestLocationUpdates method:

`public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)`

According to the documentation the minDistance is minimum distance between location updates, in meters and you have set it in 0. That means that the device will constantly acquire the users location.

George Daramouskas
  • 3,720
  • 3
  • 22
  • 51
  • "That means that the device will constantly acquire the users location." – researcher Feb 09 '15 at 13:42
  • Is there something you want me to clarify on that? – George Daramouskas Feb 09 '15 at 13:44
  • "That means that the device will constantly acquire the users location." but when i use this code, coordinates sends to server every 5min, no more. why ? I send coordinates in onLocationChanged method class LocationListener. and coordinates come to the server every 5 min, no more, not 1 min, not 1 sec.. why so? :) – researcher Feb 09 '15 at 13:52
  • In the `requestLocationUpdates` method you have a logical OR going on. If minTime is has passed since last location update **or** minDistance has been surpassed then the method is invoked. Since I assume you do not run around to get updates on your location the minDistance argument is never met, therefore you get updates on 5 minutes based on your minTime parameter. Still that is not our problem, you say you want to save battery, well my advice would be to invoke only once the method using the provider you want with a reasonable minTime and minDistance values. – George Daramouskas Feb 09 '15 at 16:57