【问题标题】:Android: battery stats show usage even after deactivating the GPS location providerAndroid:即使在停用 GPS 位置提供程序后,电池统计数据也会显示使用情况
【发布时间】:2014-07-15 18:00:57
【问题描述】:

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

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

但是,如果我禁用 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 以防万一,但仍然没有运气。

我做错了什么?

编辑:看来这毕竟不是我的应用程序的问题,我已经设法用谷歌地图重现了这个问题。

顺便说一句,我正在使用电源控制小部件。

【问题讨论】:

    标签: android gps locationmanager battery


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多