Closing the navigation drawer after opening another activity

android, navigation-drawer

Solution

You can use the new `DrawerLayout.closeDrawer(int/View, bool)` methods in v24 of the support library to instantly close a drawer:

drawerLayout.closeDrawer(Gravity.LEFT, false);

Place in your `onResume` if you want the drawer to animate closed on item click, but be closed when you go back to the activity from another one.

Problem

So I have implemented the navigation drawer and it works fine. I have action bar item that takes the uses to next activity. When entering the second activity by clicking that action bar icon, if the navigation drawer is open then it remains open even after the user returns back to first activity. I tried using ``` drawerLayout.closeDrawer(drawerListView); ``` after the intent is called but what happens is the second activity starts after the animation to close first activity is completed. This creates a bad user experience and even I dont like it. So it there any way I could close the drawer after the second activity gets created? I mean from the second activtiy's onCreate or somewhere?

Original source

Related problems