The GPS icon is still blinking after locationManager.removeUpdates () and by setting locationManager to null

I am developing a location tracking application. But I stop getting a location update by doing 2 things ...

  • locationManager.removeUpdates (this); and
  • setting locationManager links to zero.

This will stop getting location coordinates as I want ...

But the problem is that the gps icon is still blinking. This will drain the deviceโ€™s battery.

So, please help me in stopping these GPS fixes ...

+6
source share
3 answers

If you display your position and / or compass in your mapView, you must disable them. If you do not, GPS is still active.

Example:

private MapView mapView; private MyLocationOverlay Location; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.frame_layout); mapView = (MapView) this.findViewById(R.id.mapView); Location = new MyLocationOverlay(this, mapView); Location.enableMyLocation(); Location.enableCompass(); mapView.getOverlays().add(Location); } @Override public void onDestroy() { Location.disableMyLocation(); Location.disableCompass(); } 
+11
source

In addition to the answers above, in the situation you described, I would recommend that you carefully study the third-party libraries that are used in your project, especially in some analytics libraries.

I had a big headache before I realized that the GPS icon was caused by the incorrect installation of Flurry ( FlurryAgent.setReportLocation(true) was set, and onEndSession() not called in onStop() ).

+3
source

If you test this on an emulator, this is completely normal behavior. The GPS icon in the status bar never disappears.

If you test this on hardware, you called requestLocationUpdates() more than once (and did not remove other updates), or maybe something else on the hardware uses GPS.

+1
source

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


All Articles