I have an admin feature where the user is redirected to the adminHomeScreen from a screen for editing contents, now this is a button on the header part of my UI.
Now on my previous code in my common user this code does work
`
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3Api::class)
@Composable
fun HeaderComponentUser(navController: NavController?) {
TopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
containerColor = Color(0xFFFFD317)
),
navigationIcon = {
IconButton(
onClick = {
if (navController != null) {
Log.d("BACK BUTTON", "HeaderComponentAdmin: ERROR NOT WORKING") // Log for test
navController.popBackStack(Screen.Home.route, false)
// THE CODE IS THE SAME IN THE ADMIN SIDE
// navController.popBackStack(Screen.AdminHomeScreen.route, true) // <-
}
}
) {
Icon(
contentDescription = "BACK",
imageVector = Icons.Filled.KeyboardArrowLeft,
modifier = Modifier.size(32.dp),
tint = Color(0xFF000000)
)
}
},
title = {
Text(
text = "",
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Bold,
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
},
)
}'
HeaderComponentUser(navController)
this is my code for the calling header UI
`
navController.popBackStack(Screen.AdminHomeScreen.route, true)
` <- this code doesn't work to
Over all the code in the common user is the same as the admin user however it does not navigate back to AdminHomeScreen from the screen for editing contents
When you are acting as a common user, and need to go to
Screen.Home.route, you use parameterinclusive = falsein function:But, when you are acting as a admin, and need to go to
Screen.AdminHomeScreen.route, you use parameterinclusive = truein function:What is
popBackStack()in our case? This is function, what we can use for movements to back insideNavController BackStack, it and it has two required parameters:route- route of screen what you need to openinclusive- boolean value, wheninclusive = true, pops (removes) all destinations from top of BackStack to specified in the parameterroute, including specified in the parameterroute. Wheninclusive = false, pops (removes) all destinations from top of BackStack to specified in the parameterroute, but not including specified in the parameterroute.For example:
I guess, in your case, navigation does not navigate back to AdminHomeScreen from the screen for editing contents due to parameter
inclusive = true