Android Navigation Bar: How to always navigate to the main fragment when selecting an item in the navigation bar? #62690
-
Select Topic AreaQuestion BodyThere is a main fragment that is attached to a menu item in the navigation bar. There is a button in the fragment, when clicked, the next fragment opens via findNavController().navigate(R.id.action) How can I make it so that when I click on the button on the navigation bar, I reopen the main fragment? At the moment, nothing happens and I just stay in the opened child fragment. An example of such an implementation is in the YouTube application. There is a "Subscriptions" button on the navigation bar, which leads to a fragment with channels that I subscribe to. Next, you can select a channel and a fragment of the channel view will open. And if you then click on the "Subscriptions" button again, the main fragment will open again. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'm not sure if I understand your problem correctly, but try findNavController().popBackStack() (it brings you back to previous fragment) or findNavController().popBackStack(R.id.fragmentYouWantToGo, false);(it brings you back to fragment with this id |
Beta Was this translation helpful? Give feedback.
I'm not sure if I understand your problem correctly, but try findNavController().popBackStack() (it brings you back to previous fragment) or findNavController().popBackStack(R.id.fragmentYouWantToGo, false);(it brings you back to fragment with this id