Issue
let say I have 4 tabs in bottom navigation view. and if the user choose one of those tabs, then the user will navigate from one fragment to other fragments.
let say user choose the first tab (home), and then navigate from:
fragmentA (home) -> fragmentB -> fragmentC -> fragmentD -> fragmentE
I want to back from fragmentE to fragmentA programmatically using navigation controller component in Android. how to do that ?
I have tried using this code, but it just went back to fragmentD (form fragmentE)
btn.setOnClickListener{
Navigation.findNavController(view).navigateUp()
}
Solution
NavController
's popBackStack(int, boolean)
pops back to a specific destination id:
Attempts to pop the controller's back stack back to a specific destination.
Therefore you can use
Navigation.findNavController(view).popBackStack(R.id.fragmentA, false)
To pop back to fragmentA without popping fragmentA itself (which is why the inclusive
flag is false
).
Answered By - ianhanniballake
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.