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