https://kotlinlang.org logo
#compose
Title
# compose
g

Geert

02/18/2021, 2:16 PM
I just tried to add a onbackpress dispatcher to a composable function. It works, but should I place it the function, SideEffect, LaunchedEffect, or DisposableEffect? I have to add it since it needs the call popBackStack() multiple times (or popUpTo)
a

Albert Chang

02/18/2021, 2:49 PM
Should be like this:
Copy code
DisposableEffect(callback) {
    // Add callback
    onDispose {
        // Remove callback
    }
}
i

Ian Lake

02/18/2021, 2:49 PM
You should use the
BackHandler
API in Activity Compose 1.0.0-alpha02, which does all this correctly for you: https://developer.android.com/jetpack/androidx/releases/activity#1.3.0-alpha02
4
4 Views