GPS location selection never stops at ICS

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 ...

+4
source share
1 answer

I saw several sources (none of which are final) that hint that the status of the icon may not reflect the state of the GPS chip. To find out if GPS really works, you can write a test application that uses only PASSIVE_PROVIDER and launches Toast or sends a location to a text field in place if the source is GPS.

Although my phone icon seems to behave on its own, I wrote a test "dirty application" that only removes location updates in onDestroy and not in onPause. Therefore, when I launch this application and press "home", it goes into the background, but leaves the GPS turned on. If I then run the passive provider application, this will update the location.

You can do something similar to calm the mind (or otherwise).

0
source

Source: https://habr.com/ru/post/1395233/


All Articles