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

浪尽此生 提交于 2019-12-21 11:28:09

问题


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


回答1:


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();
}



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/10142113/gps-icon-is-still-blinking-after-locationmanager-removeupdates-and-by-setting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!