Skip to content Skip to sidebar Skip to footer

Navigation Drawer - Hamburger Menu Working But Back Arrow Opens The Drawer

I am using a Navigation Drawer and the hamburger menu is showing in all the right screens, but on the other fragments, when I click on the back arrow, the navigation drawer opens w

Solution 1:

The getFragmentManager().popBackStack() method is probably what you are looking for. Here's a sample snippet to be placed for activity:

@OverridepublicvoidonBackPressed(){
    FragmentManagerfm= getFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        Log.i("MainActivity", "popping backstack");
        fm.popBackStack();
    } else {
        Log.i("MainActivity", "nothing on backstack, calling super");
        super.onBackPressed();  
    }
}

In case of fragments, try calling the fragment like this:

getSupportFragmentManager().beginTransaction()
    .add(detailFragment, "detail") // Add this transaction to the back stack.addToBackStack(null)
    .commit();

Post a Comment for "Navigation Drawer - Hamburger Menu Working But Back Arrow Opens The Drawer"