From fa3f6f055cea88ad31e8e641c1c24d1b5507629a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Wed, 5 Sep 2018 11:32:48 +0200 Subject: [android] deactivating default location engine when the map is destroyed --- .../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 4 ++++ .../main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 7 +++++++ .../plugins/locationlayer/LocationLayerPlugin.java | 15 +++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 76870e44d9..83a0ef0e62 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -426,6 +426,10 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { onMapChangedListeners.clear(); mapCallback.clearOnMapReadyCallbacks(); + if (mapboxMap != null) { + mapboxMap.onDestroy(); + } + if (nativeMapView != null && hasSurface) { // null when destroying an activity programmatically mapbox-navigation-android/issues/503 nativeMapView.destroy(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 8892aa45fe..588a327839 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -158,6 +158,13 @@ public final class MapboxMap { } } + /** + * Called when the hosting Activity/Fragment onDestroy()/onDestroyView() method is called. + */ + void onDestroy() { + locationLayerPlugin.onDestroy(); + } + /** * Called before the OnMapReadyCallback is invoked. */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 021729b6ba..1fcdaa7c76 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -653,12 +653,6 @@ public final class LocationLayerPlugin { * Internal use. */ public void onStart() { - // TODO: 03.09.18 LLP when map destroyed - /*if (context.isDestroyed()) { - Logger.e("You are calling plugins #onStart after the map was destroyed. Re-create the plugin before using it."); - return; - }*/ - isPluginStarted = true; onLocationLayerStart(); } @@ -671,6 +665,15 @@ public final class LocationLayerPlugin { isPluginStarted = false; } + /** + * Internal use. + */ + public void onDestroy() { + if (locationEngine != null && usingInternalLocationEngine) { + locationEngine.deactivate(); + } + } + /** * Internal use. */ -- cgit v1.2.1