Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable back button in Jetpack Compose

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
}
like image 543
Sam Avatar asked Sep 13 '25 14:09

Sam


1 Answers

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()
    }
}
like image 69
Rajasekhar Avatar answered Sep 16 '25 09:09

Rajasekhar