jetpack compose disable back button

Viewed 2010

how can i disable the back button in jetpack compose or don't want the user to go back to previous screen,

I tried below code but, still go back to previous screen

BackHandler(enabled = false) {
       //do nothing
    }
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
            Timber.e("Clicked back")
        }

        YourDestinationScreen()
    }
}
Related