LocationListener keeps on working even after removing updates from its LocationManager and setting it to null

53 Views Asked by At

I'm trying to make a LocationListener to stop after a fragment is detached, I've checked that the following code is executed:

 @Override
    public void onDetach() {
        super.onDetach();
        locationManager.removeUpdates(locationListenerBest);
        locationListenerBest=null;
    }

Location manager starts requesting updates with this:

locationManager.requestLocationUpdates(provider, LOCATION_UPDATE_MIN_TIME, LOCATION_UPDATE_MIN_DISTANCE, locationListenerBest);

So I don't see a reason why it wouldn't just stop requesting updates once that onDetach method is executed.

Why could that happen?

Edit, due to @AlexTa request I'm showing the code used to instatiate locationManager.

locationManager =(LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
0

There are 0 best solutions below