How can I disable the back button in Jetpack Compose? I don't want the user to go back to previous screen.
I tried below code but the user can still go back to the previous screen:
BackHandler(enabled = false) {
   // do nothing
}
                You should set enabled to true for taking control of back button. Then call BackHandler from the current destination in your NavHost
NavHost(
    navController = navController,
    startDestination = startDestination
) {
    composable(
        route = "Your Destination Route"
    ) {
        BackHandler(true) {
            // Or do nothing
            Log.i("LOG_TAG", "Clicked back")
        }
        YourDestinationScreen()
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With