So I have a case where the app crashes if I call popBackStack
while the transition animation is running. Is there any clean way of stopping any ongoing transition, or at least check if anyone is running?
The exception I'm getting:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3577)
A couple of facts which may or may not be relevant to why this exception is occuring:
- I'm using standard Fragment-implementation, not supportFragment (reason being I wanted to use SettingsFragment).
- I'm using
setRetainInstance(true)
on the Fragments - I did try to remove the child view from the parent in the Fragment's
onCreateView
, but this fails for some reason (childView.getParent()
still not null after callingparentView.remove(childView)
)
Solutions I've considered:
- Set
retainInstance=false
- Wait until the animation ends before executing
popBackStack
- Finding a way to cleanly abort / reverse the transition
no.1 is not really an option since it will break the UX for the user and also cause a lot of refactoring.
no.2 is the one I'm considering most now but I don't like how I have to move code related to animation initialization and implement a bunch of code for this workaround
no.3 Is the solutioin I'd go for if I knew how. Anyone?