Skip to content Skip to sidebar Skip to footer

Navigation Drawer Doesn't Work Onbackpressed In Different Activities

I am using common navigation drawer for different activities where I am extending BaseActivity , although it works fine but i am unable to open the drawer if I pressed back button

Solution 1:

There is something wrong with your code. In onOptionsItemSelected there is wrong code. Replace that code with this code and everything should work fine:

@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
    // This makes sure the NavigationDrawer gets opened when the upper left button is pressedif (drawerToggle.onOptionsItemSelected(item)) {
        returntrue;
    }
    returnsuper.onOptionsItemSelected(item);
}

Solution 2:

If you want to do something when you come back on an activity you have to do it in onResume.

Solution 3:

Overiding OnBackPressed in class which is extending BaseClass.

@Override
    public void onBackPressed() {

        if(mDrawerLayout.isDrawerOpen(mDrawerList)){
            mDrawerLayout.closeDrawer(mDrawerList);
        }else {
          //  mDrawerLayout.openDrawer(mDrawerList);
            super.onBackPressed();
        }
    }

Post a Comment for "Navigation Drawer Doesn't Work Onbackpressed In Different Activities"