2

I have a DrawerLayout that usually works perfectly. I am using a button that opens the drawer by calling this method:

mDrawerLayout.openDrawer(mFragmentContainerView);

As I said, everything works fine but sometimes when the activity comes back from background the openDrawer method does nothing.

By using

mDrawerLayout.isDrawerOpen(mFragmentContainerView);

before and after calling the openDrawer method, I can see it is always closed.

I have spent several hours on this. What is going on? Any clue is appreciated!

Montaner
  • 522
  • 5
  • 16

1 Answers1

2

Open and close the drawer using it's gravity like this

if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
                        mDrawerLayout.closeDrawers();
                    } else {
                        mDrawerLayout.openDrawer(Gravity.START);
                    }

or use View.VISIBLE and View.GONE in place of Gravity.

Ankit Khare
  • 1,345
  • 11
  • 30
  • Thanks, but Gravity.START is not working. And View.VISIBLE or View.GONE throws an exception IlegalArgumentException "container is not a sliding drawer". – Montaner Apr 21 '15 at 20:23
  • in your darwer layout xml file the layout you are including must have gravity set to start. – Ankit Khare Apr 22 '15 at 03:58
  • Yes, the layout has gravity="start". That is why it usually works. – Montaner Apr 22 '15 at 07:27
  • then the Gravity thing should work, just add your drawer code here so that i can have a look at that. – Ankit Khare Apr 22 '15 at 07:34
  • I don't think it's a matter of Gravity. I have tried everything in that aspect. It seems that the problem arises when two instances of the activity are launched; then one of them does not open the drawer. It seems that setting the singleTask flag in the activity solves the problem, though I will do more testing... – Montaner Apr 22 '15 at 08:12