Introduction
Setting up a two pane application with two Activities and two possible fragments is discussed in several tutorials, see e.g. the tutorial from Lance Gleason. ALso the stubb code from Android Studio uses the kind of implementation.
The problem
The problem is that all tutorials only cover the static implementation method (using Fragments in XML) or use another activity, mainly to display the details in two pane mode.
Thing is, Andoroid states that a single activity application is the way to go from now on: Today we are introducing the Navigation component as a framework for structuring your in-app UI, with a focus on making a single-Activity app the preferred architecture.
The problem with the single activity solution is that if you want to save the state of your Fragment during a configration change, things become difficult.
- Although the Activity is rebooted, the Fragment is not
- Reusing the already created fragments in the Activity (which has rotated) and managing the Fragments becomes tedious and difficult to maintain. See e.g. the solution provided by Danielle B
Question
What is the best practices solution, for a dual pane architecture in Android, using only 1 Activity, two fragments, while maintaining the state of the Fragments during a configuration change?
Kind regards
Jens Buysse