LocationManager updates every minute, consuming a lot of battery power

I have code similar to the following:

LocationManager m = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_COARSE); String provider = m.getBestProvider(c, true); Intent i = new Intent(context, LocationReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); m.requestLocationUpdates(provider, 900000, 0, pi); 

Here is the manifest entry for the recipient:

 <receiver android:name=".LocationReceiver" /> 

In most cases, it works fine and is updated every 15 minutes. Sometimes, however, it is updated every minute and consumes a bunch of battery power. What am I doing wrong here?

Edit: is the LocationManager used for background use?

+2
source share
2 answers

I used a technique to which he replied: The best way to constantly monitor your location

+1
source

You can stop listening to location updates.

 // Remove the listener you previously added m.removeUpdates(locationListener); 

You probably saw this post in case you didn't say that.

http://developer.android.com/guide/topics/location/obtaining-user-location.html

0
source

Source: https://habr.com/ru/post/887055/


All Articles