[android] #5934 - resolves memory leaks on animators + location listeners
This commit is contained in:
@@ -1493,6 +1493,14 @@ public class MapView extends FrameLayout {
|
||||
if (mMapboxMap.getUiSettings().isZoomControlsEnabled()) {
|
||||
mZoomButtonsController.setVisible(false);
|
||||
}
|
||||
|
||||
// make sure we don't leak location listener
|
||||
if (mMyLocationListener != null) {
|
||||
// cleanup to prevent memory leak
|
||||
LocationServices services = LocationServices.getLocationServices(getContext());
|
||||
services.removeLocationListener(mMyLocationListener);
|
||||
mMyLocationListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Called when view is hidden and shown
|
||||
|
||||
@@ -320,11 +320,6 @@ public class MyLocationView extends View {
|
||||
setBearing(position.bearing);
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
compassListener.onPause();
|
||||
toggleGps(false);
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
if (myBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
compassListener.onResume();
|
||||
@@ -334,6 +329,37 @@ public class MyLocationView extends View {
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
compassListener.onPause();
|
||||
toggleGps(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
// cleanup to prevent memory leaks
|
||||
if (locationChangeAnimator != null) {
|
||||
locationChangeAnimator.cancel();
|
||||
locationChangeAnimator = null;
|
||||
}
|
||||
|
||||
if (accuracyAnimator != null) {
|
||||
accuracyAnimator.cancel();
|
||||
accuracyAnimator = null;
|
||||
}
|
||||
|
||||
if (directionAnimator != null) {
|
||||
directionAnimator.cancel();
|
||||
directionAnimator = null;
|
||||
}
|
||||
|
||||
if (userLocationListener != null) {
|
||||
LocationServices services = LocationServices.getLocationServices(getContext());
|
||||
services.removeLocationListener(userLocationListener);
|
||||
userLocationListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (isEnabled()) {
|
||||
myLocationBehavior.invalidate();
|
||||
|
||||
Reference in New Issue
Block a user