On our project, we have some downtime and decided to update the project target SDK version from API 26 to API 28. The project builds and works somewhat fine. The problem that we have is that we get this error when we switch back to a fragment that is in the back stack:
The specified child already has a parent. You must call
removeView()
on the child's parent first.
We have a class called BaseNavigationController
that is a fragment and manages our nested fragments. We use the getChildFragmentManager
and we set the setCustomAnimations
with enter, exit, popEnter and popExit values.
The error "disappears" when we set the duration of all the animation to the exact same length. But that it persist if we remove the setCustomAnimations
from the transaction.
getFragmentManager().beginTransaction()
.setCustomAnimations(enter, exit, popEnter, popExit)
.addToBackStack(null)
.replace(R.id.main_container, controller, tag)
.commit();
I haven't found any proper solution to this problem. One hack is to remove the view in the onDestroyView
method in the base fragment. But then we get an empty screen on the enter animation from the back stack. The other one is that we use the getFragmentManager
method but then the fragment nesting doesn`t work correctly.