After upgrade from Android support library 23.1.1
to the latest 25.1.0
the behavior from popBackStack()
has changed in our application.
For example I have three FragmentTransactions
on BackStack. Now the fourth FragmentTrsansaction is added to BackStack. FragmentTransactions are like this:
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 routes to Fragment#5 during onViewCreated()
automatically (I know, it’s ugly and I have to change this). Anyway, when I want to leave Fragment#5 I want to resume to the Fragment that has been shown prior to Fragment#4. I do this by transaction name:
getFragmentManager().popBackStack(“<CONCRETE_TRANSACTION_NAME_4>”, FragmentManager.POP_BACK_STACK_INCLUSIVE);
or this:
getFragmentManager().popBackStack(“<CONCRETE_TRANSACTION_NAME_3>”, 0);
But with this call the onCreateView()
and onViewCreated()
of Fragment#4 will be called and Fragment#5 will be added immediately to the BackStack. Even if I resume to Fragment#1 onViewCreated()
is called for every Fragment on the BackStack – for Fragment#2, Fragment#3 and Fragment#4, even if they don’t matter for the FragmentTransaction I want to return to.
Under support library 23.1.1
I successfully jump back to Fragment#3. Fragment#4 is popped inclusive without calling onViewCreated()
. This seemed more intuitive and right to me, because calling onViewCreated()
for Fragments "outside" of my FragmentTransaction seems unnecessary?
I know, addToBackStack()
only saves the transactional states and not the Fragments itself and Fragments maybe have to be recreated.
There are similar posts to that, but I want to understand why it breaks after support library update. I can’t find the change anywhere. Was this a Bug or is it a Bug now?
I'am going on to change my code.
Thanks for help!
UPDATE I've got more lifecycle issues/changes after upgrading to support-library 25.1.0. There is an Google issue where I commented my issues additionally. Currently I had to go back to the latest 24.2.1 and keep an eye on this topic. This is just my temporary solution. These issues start with support-library 25.0.0.
Pay attention to the new support 25.1.0.
Something changed in the fragment lifecycle.
Now there is new functionality to optimize the operations and postpone fragment transitions.
Read this: https://code.google.com/p/android/issues/detail?id=230415
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