Issue
I am using One Activity, many fragments in my android app.
I have One Main Activity with Navhost. And 3 Fragments. fragment1 as home fragment which is starting point of navigation. fragment1 navigates to fragment2, fragment 2 navigates to fragment3.
From fragment3, it navigates to home fragment i.e, fragment1.
After reaching from fragment 3 to fragment 1, if I back press in fragment1, it is again navigating to fragment3 instead of exiting the app.
How should I disable the back navigation from home fragment to fragment3.
I've used
navController.navigate(navController.getGraph().getStartDestination());
in the fragment3. Not working.
Solution
I tried this and it worked.
navController.popBackStack(R.id.fragment2,true);
navController.popBackStack(R.id.fragment3,true);
navController.navigate(navController.getGraph().getStartDestination());
Answered By - Cnu Federer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.