Android:电池统计信息即使在停用GPS位置提供商后也会显示使用情况

时间:2014-07-15 18:00:58

标签: android gps locationmanager battery

我正在创建一个使用粘性LocationManager中的Service来监听位置事件的应用。

如果我使用应用活动中的启动/停止功能,一切都按预期工作。

但是,如果我禁用GPS提供商(来自Android设置),电池状态显示我的应用仍在耗尽电量(GPS使用时间计数器增加)。

这是我在应用中为启动/停止做的事情:

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);
}

这是onDestroy()逻辑:

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

    super.onDestroy();
}

这就是我处理被禁用的提供程序的地方:

@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显示该服务自行停止并调用onDestroy()

我甚至尝试将Service设置为START_NOT_STICKY以防万一,但仍然没有运气。

我做错了什么?

编辑:看起来我的应用程序不是问题,我已经设法通过Google地图重现了这个问题。

我正在使用Power Control小部件btw。

1 个答案:

答案 0 :(得分:1)