After updating from the Android 23.1.1 support library to the latest version 25.1.0 , the behavior from popBackStack() in our application changed.
For example, I have three FragmentTransactions on a BackStack. Now the fourth FragmentTrsansaction is added to BackStack. FragmentTransactions is as follows:
FragmentTransaction transaction = fragmentManager.beginTransaction() .replace(R.id.fragment_container_single, target, CoreActivity.FRAGMENT_TAG_LEFT) .addToBackStack(<CONCRETE_TRANSACTION_NAME>) .commit();
Fragment # 4 has logic, where it is automatically routed to Fragment # 5 during onViewCreated() (I know its ugly, and I have to change that). In any case, when I want to leave fragment No. 5, I want to return to the fragment that was shown before fragment No. 4. I do this by the name of the transaction:
getFragmentManager().popBackStack("<CONCRETE_TRANSACTION_NAME_4>", FragmentManager.POP_BACK_STACK_INCLUSIVE);
or that:
getFragmentManager().popBackStack("<CONCRETE_TRANSACTION_NAME_3>", 0);
But with this call, onCreateView() and onViewCreated() fragment # 4 will be called, and fragment No. 5 will be immediately added to BackStack. Even if I go back to fragment # 1, onViewCreated() is called for every fragment on BackStack β for fragment # 2, fragment # 3 and fragment # 4, even if they don't matter for the FragmentTransaction that I want to return to.
In the support library 23.1.1 I will successfully return to fragment # 3. Fragment No. 4 is included without calling onViewCreated() . This seemed more intuitive and correct for me because calling onViewCreated() for fragments "outside" of my FragmentTransaction seems unnecessary?
I know addToBackStack() only saves transactional states, not the fragments themselves, and fragments may need to be recreated.
Similar to posts , but I want to understand why it breaks after updating the support library. I canβt find the changes anywhere. Was this a mistake or is it a mistake now?
I am going to change my code.
Thanks for the help!
UPDATE I have more problems with the life cycle / changes after upgrading to support library 25.1.0. There is a Google issue where I additionally commented on my concerns. Currently, I had to go back to the last 24.2.1 and follow this topic. This is only my temporary solution. These problems start with support-library 25.0.0.