diff --git a/src/main/java/com/mapconductor/longdo/LongdoMapView.kt b/src/main/java/com/mapconductor/longdo/LongdoMapView.kt index 445220f..35ec922 100644 --- a/src/main/java/com/mapconductor/longdo/LongdoMapView.kt +++ b/src/main/java/com/mapconductor/longdo/LongdoMapView.kt @@ -530,6 +530,17 @@ fun LongdoMapSurface( onDispose { moveDispatcher.cancel() controller.destroy() + // No MapViewBase here to do it: the state (which the app keeps) must + // not hold on to the destroyed controller and its overlays. + state.detachController(controller) + // The WebView is the map. Not destroyed, it keeps its renderer and + // the JS bridge, and through them the controller with every overlay. + // This runs for a configuration change too: the old Activity's + // WebView is never shown again (the state is what survives). + (longdoMap.parent as? ViewGroup)?.removeView(longdoMap) + longdoMap.removeJavascriptInterface(BRIDGE_NAME) + longdoMap.stopLoading() + longdoMap.destroy() } } } diff --git a/src/main/java/com/mapconductor/longdo/LongdoViewStateImpl.kt b/src/main/java/com/mapconductor/longdo/LongdoViewStateImpl.kt index 0e689e7..fa86655 100644 --- a/src/main/java/com/mapconductor/longdo/LongdoViewStateImpl.kt +++ b/src/main/java/com/mapconductor/longdo/LongdoViewStateImpl.kt @@ -38,7 +38,10 @@ class LongdoViewState( LongdoViewStateInterface { private var _mapDesignType by mutableStateOf(mapDesignType) - private var controller: LongdoMapViewController? = null + // Read through the base so that letting go of the controller there (MapViewBase + // does it when the map is torn down) leaves nothing behind here. + private val controller: LongdoMapViewController? + get() = attachedMapController as? LongdoMapViewController override var mapDesignType: LongdoMapDesignTypeInterface get() = _mapDesignType @@ -49,7 +52,6 @@ class LongdoViewState( /** MapView 生成時にコントローラを紐付ける。 */ fun setController(controller: LongdoMapViewController) { - this.controller = controller // 初期カメラは LongdoMap.LOCATION として地図読み込み前に渡すので、接続時には移動しない。 attachController(controller, moveToInitialCamera = false) }