• 9

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Destinations chaining in Android Navigation Components

I have a simple navigation graph like this:

MainFragment -> ListFragment -> DetailFragment

How can I achieve a "shortcut" from MainFragment to DetailFragment, so that:

  • UP navigation from DetailFragment will navigate to ListFragment within the graph and
  • BACK navigation from DetailFragment will return to MainFragment (optionally, BACK could behave as UP)

Is this possible? Thanks for suggestions!

EDIT: My Solution

I can simply navigate to ListFragment first and then immediately to DetailFragment like this (I call both "navigate" calls from MainFragment):


According to documentation, which says, that "... Up button should function identically to the system Back button", I decided not to make differences between BACK and UP actions.

To move through fragments using the navigation components you should link them in the navigation graph, go to app-> res-> navigation-> graphName.xml (In the picture I use placeholders, use your fragments instead).

As you can see in the documentation to navigate from one fragment to another you need to use this line Navigation.findNavController(view).navigate(R.id.viewTransactionsAction); Where viewTransactionsAction should be the id of the arrow (in the graph) from one fragment to the next.

enter image description here

To override the back button action use:

@Override public boolean onSupportNavigateUp() { return Navigation.findNavController(this, R.id.nav_host_fragment).navigateUp(); }

And replace inside the navigation nav_host_fragment to the arrow id of the page you want to navigate to.

  • 1
Reply Report
      • 1
    • Thank you for reply, I figured out that I can simply call navigate multiple times from MainFragment, so I navigate from MainFragment to detail like this: findNavController().navigate(MainFragmentDirections.toListFragment()) and immediately findNavController().navigate(ListFragmentDirections.toDetailFragment(data)). :-) Also I found in docs, that "Up button should function identically to the system Back button" so I decided not to make diffecences between Back and Up. :-)