I’m using a FragmentActivity to display a stack of Fragments in a single activity app. This is working fine and I can move through the fragments and hit back to go back up the stack until I rotate the device when I end up with the Fragment on the top of the stack rotated but hitting the back button takes me back to the root Fragment with all other Fragments in between gone.
I’m using the following code to add a Fragment to the stack:
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.mainContentViewContainer, newFragment, "DetailFragment");
transaction.addToBackStack(null);
transaction.commit();
What could be causing the stack to be empty after rotate?
Forcing android to not restart the Activity, adding
android:configChangesintoAndroidManifest.xml, is wrong.Keeping this in mind:
Due of the Android behaviour, when you rotate the screen the MainActivity will be restarted. You can override this behaviour with the
android:configChangesoption of the AndroidManifest file.