As of SDK 26.0.0-beta1 and above, making use of the getFragments
https://developer.android.com/reference/android/support/v4/app/FragmentManager.html#getFragments() method returns a list with only 1 fragment and the size of the list is also always 1 (so this excludes any possible null entries that might have been misleading me), when using replace
method for fragment navigation.
Keep in mind I am using getSupportFragmentManager
, not getFragmentManager
Prior to this SDK version all fragment transactions done with replace
would be listed in the getFragments
method. This means that if I replaced 10 fragments then the getFragments
would return a list containing all of those 10 fragments.
However, from SDK 26.0.0-beta1 - specifically - and above (26.0.0-alpha1 and below does not have this problem) the method always returns a list of size 1 containing only the last fragment that was replaced.
To circumvent this problem I started using add
and hiding whichever was the previously visible fragment, and so far this worked for what I wanted, which was to check which is the first fragment in the getFragments
list whenever I needed as well as seeing if a certain instance of a fragment is already in that list.
Now a new problem arises when I try to use shared elements transitions, which only works with replace
(as far as my google fu allowed me to find) meaning that if I want to use shared elements transitions I have to return to using replace
fragments instead of add
, but I will be back to the initial problem again.
So now I am stuck in this predicament and hoping anyone has a solution for this:
- Is there any way to fix this?
- Is the
getFragments
suppose to only return 1 fragment when we only use thereplace
method or is this behavior an undocumented bug that is yet to be fixed? - Is it possible to make shared element transitions between fragments without using
replace
?