我試圖做一個兩步的位置檢測與我LocationListener
。按預期在每個Android版本上按預期工作。只有在ICS上,我無法停止GPS位置檢測。GPS定位取永遠不會停止對ICS
// inner class inside my PoiActivity
private class CustomLocationListener implements LocationListener {
String currentProvider = LocationManager.NETWORK_PROVIDER;
@Override
public void onLocationChanged(Location location) {
if (location != null) {
if (currentProvider.equals(LocationManager.NETWORK_PROVIDER)) {
System.out.println(this);
mLastKnownLocation = location;
mHandler.sendEmptyMessage(0);
mLocationManager.removeUpdates(this);
Log.i("CustomLocationListener", "Got a rough location, removing the network listener ");
Toast.makeText(PoiActivity.this, "Network found and removed", Toast.LENGTH_LONG).show();
mLocationManager
.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, Constants.LOCATION_MAX_ACCURACY, this);
currentProvider = LocationManager.GPS_PROVIDER;
} else if (location.getAccuracy() < Constants.LOCATION_MAX_ACCURACY
&& currentProvider.equals(LocationManager.GPS_PROVIDER)) {
System.out.println(this);
mLastKnownLocation = location;
mHandler.sendEmptyMessage(0);
mLocationManager.removeUpdates(this);
Log.i("CustomLocationListener", "Got a rough location, removing the gps listener ");
Toast.makeText(PoiActivity.this, "GPS found and removed", Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
基於Toast和LogCat信息,監聽器被刪除,除ICS以外的每個版本,我看到GPS圖標消失。在ICS上,這個圖標在幾秒鐘後重新出現,但我從來沒有多次收到過Toasts,所以我的聽衆被成功刪除了。
查殺應用程序與任務管理器或通過應用信息不會停止GPS圖標,一次又一次出現。
我想這是一個特定的ICS的問題,但我無法找到該或類似的問題描述的bug報告。
有人有解決方法嗎?因爲我不希望用戶得到的是我拉了幾次,沒有任何好處消耗電池,其暗示的感覺...