[android] deactivating default location engine when the map is destroyed

This commit is contained in:
Łukasz Paczos
2018-09-05 11:32:48 +02:00
committed by Łukasz Paczos
parent bfe0b67572
commit fa3f6f055c
3 changed files with 20 additions and 6 deletions

View File

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

View File

@@ -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.
*/

View File

@@ -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.
*/