Status Update
Comments
ap...@google.com <ap...@google.com> #2
As a general note, what you're checking makes little sense - onAttachFragment
is called as fragments move through their lifecycle methods (specifically, right after onAttach()
is called on the fragment) and is therefore likely to be called while FragmentTransactions are being processed - if you have multiple commit()
s in flight, the state you get back in onAttachFragment
will certainly not be the final state the FragmentManager will be when all of the FragmentTransactions are executed, making this a bit of a meaningless check.
That being said, this is caused by the mechanism used to kick off transitions when reordering is not allowed, which is being reworked in
As a workaround, you can use setReorderingAllowed(true)
on your transaction, which will allow your example project to work correctly.
Description
Component used: Fragment
Allow developers to detect when they are reusing a fragment instance after it was previously removed from a FragmentManager (i.e., that
initState()
was called).Ideally, this should also change the
require***()
methods to change their error message based on whether the fragment was never added (the current error message) or if it was previously added but has since been removed (a new error message).This would probably have to hook into both the
FragmentTransaction
methods for adding a fragment (to provide better stack traces) as well as in the internaladdFragment()
to ensure that Fragments that were removed as part of an inflight transaction are properly caught.