I have four fragments already set up in my app using Navigation Components:
I can go from MainFragment to MoviesFragment or TrailersFragment as well as from the UserFragment to one of them.
From the MainFragment
I can simply navigate to the MoviesFragment fragment using this code:
ActionMainFragmentToMoviesFragment action = actionMainFragmentToMoviesFragment();
action.setFromMainFragment(true);
Navigation.findNavController(rootView).navigate(action);
To navigate to the TrailersFragment fragment, I'm using similar code. When I use:
.setFromMainFragment(true);
In MoviesFragment for instance, I can simply get a boolean from the Bundle so I can know from which fragment I'm coming from, either from MainFragmnet or UserFragment and it workd very well.
And here comes the problem. When I want to get from MoviesFragment back to MainFragment, I don't navigate as above, I just press the back button. So the problem is that I don't know in the MainFragment from which fragment I'm returning (MoviesFragment or TrailersFragment).
What should I do to know from which fragment I'm coming from in MainFragment?