Answer to
@maohieng helped me, but he set the wrong title if the box was open when the orientation changed (this was the screen name, not the name of the application, as it should). Therefore, I have implemented this code, which perfectly fixes the problem.
On onSaveInstanceState() I use a boolean to verify that the box is open. It seems odd, but isDrawerOpen(mDrawer) returns false after changing the orientation when I call it onCreate ():
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putCharSequence("title", mTitle); outState.putBoolean("isDrawerOpen", mDrawerLayout.isDrawerOpen(mDrawerLinear)); }
In onCreate() activity:
if (savedInstanceState == null) { selectItem(YOUR_FRAGMENT); } else { if (savedInstanceState.getBoolean("isDrawerOpen")) { mTitle = savedInstanceState.getCharSequence("title"); } else { setTitle(savedInstanceState.getCharSequence("title")); } }
source share