I just tried to add a onbackpress dispatcher to a ...
# compose
g
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
Should be like this:
Copy code
DisposableEffect(callback) {
    // Add callback
    onDispose {
        // Remove callback
    }
}
i
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