Skip to content
🤔 Documentation issue? Report or edit

BackHandler

You can use BackHandler to detect the presses on the device back button inside of Compose

Example

@Composable
fun BackHandlerExample() {
    var backPressedCount by remember { mutableStateOf(0) }
    BackHandler(enabled = true, onBack = {
        backPressedCount += 1
    })
    Text(text="Backbutton was pressed : $backPressedCount times")
}

See also:


Last update: October 13, 2021
Back to top