I am trying to do two-step location detection using LocationListener . It works as expected on every version of Android, as expected. Only on ICS can I not stop GPS location detection.
// 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) {} }
Based on Toast and LogCat data, the listener is deleted, and on every version except ICS, I see that the GPS icon disappears. On ICS, the icon appears again after a couple of seconds, but I never received toasts more than once, so my listener was successfully deleted.
Killing an application by task manager or using application information does not stop displaying the GPS icon again and again.
I assume this is a specific ICS problem, but I cannot find an error report for this or similar problem descriptions.
Does anyone have a workaround? Because I do not want the user to feel that I pull several times and consume the battery without any benefit ...
source share