10

I'm using the Navigation Architecture Component and I have a setup similar to this one for popping the stack when navigating to a particular fragment:

<action android:id="@+id/navigate_to_main_screen" app:destination="@id/fragment_main_screen" app:popUpTo="@+id/navigation_main" app:popUpToInclusive="true"/> 

This works almost as expected. Both the system back button and the up icon in the app bar don't navigate to the previous fragment. The system back button exits the app.

However, the up button in the app bar is still there, clicking it doesn't do anything as expected. What am I doing wrong? Why is this still here?

In the main activity I already have

AppBarConfiguration config = new AppBarConfiguration.Builder(navController.getGraph()).build(); NavigationUI.setupActionBarWithNavController(this, navController, config); 

and

@Override public boolean onSupportNavigateUp() { return navController.navigateUp() || super.onSupportNavigateUp(); } 

As per the documentation.

The library version I'm using:

implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha09' implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha09' 

1 Answer 1

10

If you want to customize which destinations are considered top-level destinations, you can instead pass a set of destination IDs to the constructor, as shown below.

To solve your problem, replace

AppBarConfiguration config = new AppBarConfiguration.Builder(navController.getGraph()).build(); 

With

AppBarConfiguration config = new AppBarConfiguration.Builder(R.id.navigation_main, R.id.fragment_main_screen).build(); 

More details here: AppBarConfiguration

Sign up to request clarification or add additional context in comments.

1 Comment

Is ActionBar / DrawerLayout required for it to work?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.