[android] #5934 - resolves memory leaks on animators + location listeners

This commit is contained in:
Tobrun
2016-08-11 17:33:02 -04:00
parent a3e20bae32
commit 0ae941d2a8
4 changed files with 58 additions and 12 deletions

View File

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

View File

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