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:configChanges into AndroidManifest.xml, is wrong.
Keeping this in mind:
What could be causing the stack to be empty after rotate?
Due of the Android behaviour, when you rotate the screen the MainActivity will be restarted. You can override this behaviour with the android:configChanges option of the AndroidManifest file.
android:configChanges="orientation|screenSize"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With