I'm getting really confused about this. I have an actionbar
with list navigation. I click on the list to open 2 fragment
one after another and display in the same activity. I'm basically replacing them using this method:
public void openFragment(AprilAppsFragment createdFragment){
if (createdFragment.getClass().isInstance(getDisplayedFragment()))
return;
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.replace( R.id.main_fragment, createdFragment, "displayed fragment");
transaction.addToBackStack(null);
transaction.commit();
}
I open fragment A, then I open fragment B, then I rotate the screen. Fragment A is being recreated crashing my app
Whys is that, since I'm using replace? How do I avoid recreating fragments that no longer being shown, without losing possibility of back-pressing to them?