0

The Android documentation says

Call syncState() from your Activity's onPostCreate to synchronize the indicator with the state of the linked DrawerLayout after onRestoreInstanceState has occurred.

https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html

But the Navigation Drawer activity already implemented as a ready-made activity in Android Studio 3.0 calls that method in onCreate.

So which one is correct? Have there been changes recently?

Florian Walther
  • 6,237
  • 5
  • 46
  • 104
  • The documentation is correct. Do it in `onPostCreate()`. Likely just a slip-up in the Android Studio template. – Mike M. Mar 17 '18 at 00:10
  • OK thank you. Can you tell me what problems it could cause in onCreate? – Florian Walther Mar 17 '18 at 04:55
  • `DrawerLayout` saves and restores its drawer state during a configuration change - e.g., rotating the device - but the restore won't happen until after `onCreate()`, so if you sync in `onCreate()`, you could end up with the drawer open, but with the toggle icon in its closed state, the hamburger. – Mike M. Mar 17 '18 at 05:03
  • 1
    OK thank you very much! – Florian Walther Mar 17 '18 at 05:14

0 Answers0