Search code examples
android-jetpack-composeandroid-jetpack-navigationonbackpressed

Is there any way to override the back stack button to go back to a screen with its index in jetpack compose?


Is there any way to override onBackPress to go back to a screen with its index in jetpack compose? For example, go back to the second previous screen.


Solution

  • You can with backhandler function;

    BackHandler(
       enabled = //condition if you want.
    ) {
       // Navigate where ever you want.
       //Example;
       navController.navigate(
          route = navController.backQueue[i].destination.route.toString()
       )
    }