title: Back/Up Arrow not working when using navigation drawer
body: <p>The back or up button is not working when using a navigation drawer. The icon changes from a hamburger (having set the top level destinations) but both open the navigation drawer. I want the back/up arrow to go back in the stack.</p>
  <p>public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, DrawerLocker {</p>
  <pre><code>public static final String TAG = MainActivity.class.getSimpleName();
  
  private DrawerLayout drawerLayout;
  private NavigationView navView;
  private Toolbar toolbar;
  
  private NavController navController;
  private ActionBarDrawerToggle drawerToggle;
  
  
  private AppBarConfiguration appBarConfiguration;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      toolbar = findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
  
      //configure drawer layout
      drawerLayout = findViewById(R.id.drawer_layout);
      navView = findViewById(R.id.drawer_navigation_view);
  
      navController = Navigation.findNavController(this,R.id.nav_host_fragment);
  
      appBarConfiguration = new AppBarConfiguration.Builder(R.id.scenarioListFragment,
              R.id.tokenListFragment, R.id.settingsFragment,R.id.historyFragment)
              .setDrawerLayout(drawerLayout)
              .build();
  
      NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
      NavigationUI.setupWithNavController(navView, navController);
  
      navView.setNavigationItemSelectedListener(this);
  
      drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  
      drawerLayout.addDrawerListener(drawerToggle);
      drawerToggle.syncState();
  
      if (savedInstanceState == null ) {
          navView.setCheckedItem(R.id.drawer_menu_scenario);
          toolbar.setTitle(&quot;Scenarios&quot;);
      }
  }
  </code></pre>
  <p>I watched <a href="https://www.youtube.com/watch?v=wv5VFEcnb-8" rel="nofollow noreferrer">this video</a>, which made it seem sort of simple, but it is referring to Kotlin and my code is not far off.</p>
  <p><a href="https://stackoverflow.com/questions/56219768/toolbars-back-button-not-working-when-using-with-navigation-drawer">This post</a> covers a similar challenge as well, though in Kotlin I tried adding a setNavigationOnClickListener and put a logd statement in it. It never got fired, but the solution itself seemed like it shouldn't be necessary.</p>
  <p><a href="https://stackoverflow.com/questions/60030589/how-to-make-up-button-go-back-instead-of-opening-navigation-drawer">This post</a> seems to have cover the same issue but there are no answers. One of the responses says to setupActionBarWithNavController, which I have:</p>
  <pre><code>NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
  </code></pre>
  <p>This function has a lot of overloads and I've tried a number of them, but they seem to cause me to lose the set of top level destinations (hamburger icon for multiple fragments) and undue my the navigation which is working.</p>
  <p>I tried to follow <a href="https://developer.android.com/guide/navigation/navigation-ui#add_a_navigation_drawer" rel="nofollow noreferrer">this documentation</a>, but it only seemed to step me back from where I was. This call:</p>
  <pre><code>    AppBarConfiguration appBarConfiguration =
              new AppBarConfiguration.Builder(navController.getGraph())
                      .setDrawerLayout(drawerLayout)
                      .build();
  </code></pre>
  <p>Seems to replace the topLevelDestinations and use the navController.getGraph(), but since I have multiple ones, I have been referencing the <a href="https://developer.android.com/guide/navigation/navigation-ui#appbarconfiguration" rel="nofollow noreferrer">fragments themselves</a>.</p>
  <p>I did <a href="https://stackoverflow.com/questions/63525227/navigation-drawer-hamburger-menu-working-but-back-arrow-opens-the-drawer">ask</a> about this problem previously but it was clear to me I did not explain it well (answers addressed how to pop back and not why the back arrow was not working). I would have deleted it but people did answer and the guidance SO provided was that I should not delete it in that case. I am sorry if I caused confusion.</p>