Search code examples
androidgpslistenerlocationmanagerlocationlistener

GPS stays activated after finish()


from an Activity (UI) I call a class to get my location. At onPause in the activity I try to stop the Listeners, but the GPS icon in the status bar keeps blinking, this is the case on more devices (I read that it´s a HTC issue).

Can anybody tell me how I can fix this issue?

The GPS location class:

public GPSLocation (Context context) {
            myContext = context;

            LocatieManager=(LocationManager)myContext.getSystemService(Context.LOCATION_SERVICE);
        }   

public void StopLocationListeners(){
     // LocationManager LocatieManager=(LocationManager)myContext.getSystemService(Context.LOCATION_SERVICE);
      LocatieManager.removeUpdates(netwerklistener);
      LocatieManager.removeUpdates(gpslistener);    
      LocatieManager.removeGpsStatusListener(gpsStatusListener);
}

From the UI activity, I call mGPSLocation.StopLocationListeners(); in the onPause method, but this doesn´t work. Anybody can help me out and give a hint why this is not possible?

Thanks


Solution

  • You are closing GPS from public methods. but how can you be so sure that, the object which is currently running is getting close ? what I mean to say is you might have more than one object of your location class. you need to use static for such purpose, so that while closing GPS it will close the particular one only.