Search code examples
androidgpslocationmanagerbattery

Android: battery stats show usage even after deactivating the GPS location provider


I'm creating an app that uses the LocationManager in a sticky Service to listen for location events.

If I use the start/stop functionality from my app's activity, everything is working as expected.

However, if I disable the GPS provider (from the Android settings), battery stats shows my app as still draining battery (GPS usage time counter increases).

Here's what I do in my app for start/stop:

private void doStart() {
    Intent i = new Intent(getApplicationContext(), LocationService.class);

    getApplicationContext().startService(i);
}

private void doStop() {
    Intent i = new Intent(getApplicationContext(), LocationService.class);

    getApplicationContext().stopService(i);
}

This is the onDestroy() logic:

@Override
public void onDestroy() {
    locationManager.removeUpdates(this);
    locationManager = null;

    super.onDestroy();
}

And this is where I handle the provider being disabled:

@Override
public void onProviderDisabled(String provider) {
    String ourProvider = Utils.getCurrentLocationProvider(this);

    if (provider.equalsIgnoreCase(ourProvider)) {
        Utils.debug(TAG, String.format("'%s' == '%s', stopping self", provider, ourProvider));

        stopSelf();
    }
}

logcat shows that the service stops itself and onDestroy() is called.

I've even tried setting the Service to START_NOT_STICKY just in case, but still no luck.

What am I doing wrong?

EDIT: Looks like it's not an issue with my app after all, I've managed to reproduce this issue with Google Maps.

I am using the Power Control widget btw.


Solution

  • Android Open Source Project bug report: https://code.google.com/p/android/issues/detail?id=73628