synic
synic

Reputation: 26668

LocationManager updates every minute, consuming a lot of battery power

I've got some 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 receiver:

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

Most of the time it works fine, and updates every 15 minutes. Sometimes, however, it updates every minute, and consumes a bunch of battery power. What am I doing wrong here?

Edit: Is the LocationManager not meant to be used like this for background operations?

Upvotes: 2

Views: 2259

Answers (2)

synic
synic

Reputation: 26668

I used the technique answered here: Best way to constantly monitor location

Upvotes: 1

Yekmer Simsek
Yekmer Simsek

Reputation: 4102

You can stop listening for location updates

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

Probably you have seen this post, in case of you did not it is told here

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

Upvotes: 0

Related Questions