7

I am developing the Location Tracking application. But i am stopping getting the location update by doing 2 things...

  1. locationManager.removeUpdates(this); and
  2. setting locationManager reference to null.

This will stop getting location co-ordinates as i want...

But the problem is the gps icon is still blinking.. which will draining the device's battery.

So please help me in stopping this GPS fixes...

NullPointerException
  • 3,978
  • 4
  • 34
  • 52

3 Answers3

11

If you display your position and/or the compass in your mapView, you have to disable them. If you don't do that, GPS is still active.

Ex :

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();
}
JoMoX909
  • 125
  • 5
  • 4
    This was the answer for me. Thanks! For the updated Google Maps api I had do this: `map.setMyLocationEnabled(false);` – Robert Sep 15 '15 at 23:22
3

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

I had a big headache before I realized that GPS icon was caused by Flurry that was incorrectly installed (FlurryAgent.setReportLocation(true) was set and onEndSession() wasn't called in onStop()).

Andrei Buneyeu
  • 6,662
  • 6
  • 35
  • 38
2

If you are testing this on the emulator, this is perfectly normal behavior. The GPS icon in the status bar never goes away.

If you are testing this on hardware, either you have called requestLocationUpdates() more than once (and have not removed the other updates), or perhaps something else on the hardware is using GPS.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thx sir, I m testing on device..But my code is like when timer hits i request the locationManager to get updates by locationManager.requestLocationUpdates(bestProvider,10 * 1000, 1, listener); then in the listener i hv written public void onLocationChanged(Location location) { FileUtils.save(location, mContext); locationManager.removeUpdates(this); } So according to my opinion there is no way that my code is requesting to updates anymore... So please tell me any code modification i hv to do.. – NullPointerException Apr 14 '12 at 09:46
  • Although I do removeUpdates for all the requestLocationUpdates I initiated, it happens to me on some devices only, like the Samsung Galaxy S2. It seems however that the GPS blinking icon does go away after a few more seconds (usually less than 30) – Erwan May 29 '13 at 07:20