Composable Function

rememberSpatialActivityPanelController

Creates and remembers a SpatialActivityPanelController across recompositions.

SpatialActivityPanelSample

@Sampled
@Composable
public fun SpatialActivityPanelSample(intent: Intent) {
    // Because the controller is remembered, passing a different intent parameter
    // on recomposition will not update the controller or launch a new activity.
    val controller = rememberSpatialActivityPanelController(intent)

    Subspace { SpatialActivityPanel(controller = controller) }
}

SpatialActivityPanelRecreateSample

@Sampled
@Composable
public fun SpatialActivityPanelRecreateSample() {
    val context = LocalContext.current
    var selectedEmailId by remember { mutableStateOf<String?>(null) }

    Column {
        Button(onClick = { selectedEmailId = "email_1" }) { Text("Open Email 1") }

        Button(onClick = { selectedEmailId = "email_2" }) { Text("Open Email 2") }

        if (selectedEmailId != null) {
            Subspace {
                // Using Compose key to force recreation of the controller and
                // the panel whenever the selected email changes. This tears down
                // the old activity stack and starts a new one for the new email.
                key(selectedEmailId) {
                    val intent =
                        Intent(context, NewEmailActivity::class.java).apply {
                            putExtra("EMAIL_ID", selectedEmailId)
                        }
                    SpatialActivityPanel(
                        controller = rememberSpatialActivityPanelController(intent)
                    )
                }
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: