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 :
- App launched in landscape mode
- Landscape Layout - Dual Pane is inflated and data loaded
- Orientation changed
- Menu fragment destroyed and detached
- Portrait Layout - Navigation Drawer with content fragment inflated
- Navigation drawer attached to activity and detached immediately
- * Because Landscape Menu Fragment is re-created by the system and attached to the activity.*
- 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 ?