I’m new to AndroidView interop, and have a questio...
# compose
b
I’m new to AndroidView interop, and have a question about the
MapView
(or maybe really a question about the
LocalLifecycleOwner
Composition Local) that is used in the *Crane Sample app*…. The app uses a separate activity for the Details screen which contains the
MapView
. The
MapView
follows the lifecycle of the
LocalLifecycleOwner
(by setting up an observer on the owner’s lifecycle and calling the corresponding MapView method when the lifecycle’s state changes). I guess my question is whether that setup is “binding” the MapView to the lifecycle of the Activity, or the lifecycle of the composition in which it’s used? For example, in the (parent)
DetailsContent
composable, say I were to setup a boolean state value that gets toggled when clicking on one of the Text composables. And then I wrap the call to the
CityMapView
composable to only get called when the state value is true (thus creating the ability to toggle the map display on an off). If I then click on the text and toggle the map display off (
CityMapView
leaves the composition), will the MapView have it’s onStop and onDestroy methods called? Or is it “bound” to the activity, and it will continue to exist (and be resumed) since the activity’s lifecycle still exists and is resumed? if that is the case, it seems like toggling it on and off would be problematic.
here’s an demo of the example toggling scenario I described ``
Copy code
@Composable
fun DetailsContent(
    exploreModel: ExploreModel,
    modifier: Modifier = Modifier
) {
    var showMap by remember { mutableStateOf(true) }

    Column(modifier = modifier, verticalArrangement = Arrangement.Center) {
        Spacer(Modifier.height(32.dp))
        Text(
            modifier = Modifier.align(Alignment.CenterHorizontally)
                .clickable { showMap = !showMap },
            text = exploreModel.city.nameToDisplay,
            style = MaterialTheme.typography.h4,
            textAlign = TextAlign.Center
        )
        Text(
            modifier = Modifier.align(Alignment.CenterHorizontally),
            text = exploreModel.description,
            style = MaterialTheme.typography.h6,
            textAlign = TextAlign.Center
        )
        Spacer(Modifier.height(16.dp))
        if (showMap) {
            CityMapView(exploreModel.city.latitude, exploreModel.city.longitude)
        }
    }
}