0

Here is the layout design for my tablet portrait and landscape

  • Portrait layout
    • Menu Navigation Drawer and
    • Content Fragment
  • Landscape layout (Dual Pane)
    • Menu Fragment on the left
    • Content Fragment on the right

I am using support library for the navigation drawer android.support.v4.widget.DrawerLayout

Usecase :

  1. App launched in landscape mode
  2. Landscape Layout - Dual Pane is inflated and data loaded
  3. Orientation changed
  4. Menu fragment destroyed and detached
  5. Portrait Layout - Navigation Drawer with content fragment inflated
  6. Navigation drawer attached to activity and detached immediately
  7. * Because Landscape Menu Fragment is re-created by the system and attached to the activity.*
  8. App crashes because Navigation Drawer is detached

I tried a solution suggested by a stackoverflow user goRGon and it seems to work.

But need your suggestions whether this is the best way to stop a fragment recreation ?

Community
  • 1
  • 1
Akh
  • 5,961
  • 14
  • 53
  • 82
  • I wouldn't use the solution you linked to. From what I understood your scenario looks quite simple, something like this https://gist.github.com/luksprog/7c8523f3e3a0886081ec – user Feb 09 '15 at 23:03
  • I have a similar layout except for the fragment inside the drawer instead of framelayout. Would it make a difference? – Akh Feb 09 '15 at 23:41
  • Yes, it should make a difference. – user Feb 09 '15 at 23:43
  • Thanks Luksprog. Changing Fragment to FrameLayout doesn't help. Any suggestions – Akh Feb 10 '15 at 00:08
  • What I said above should work, I even made a small sample(basic stuff) https://github.com/luksprog/DrawerWithOrientation .I'm assuming that you get the exception due to the DrawerLayout not being in the landscape layout, which indeed need to be handled manually in code. – user Feb 10 '15 at 12:55

0 Answers0