0

I am using Navigation Component to navigate through pages in my app.

I have a ProfileFragment and users might navigate to this fragment from different fragments(like HomeFragment, ArticleFragment, and ...).

In my ProfileFragment how should I know where to navigate the user to the previous page before they opened Profile. When the user pressed Back Button how am I supposed to detect the right action.

In my fragment's toolbar, I have an arrow (ImageButton) for navigation to the previous page too. How should I handle it in its onClickListener?

Here you can see the graph of my navigation.xml

1 Answers1

1

When user clicks the back arrow in the Toolbar, you can call findNavController().popBackStack(). This will move user to the last fragment in the back stack, regardless of which one was visible before (before moving to ProfileFragment).

Gil Becker
  • 283
  • 1
  • 9