Reputation: 2576
I want to re-create Fragment. After I did something like
fragmentTransaction.detach(someFragment);
fragmentTransaction.attach(someFragment);
fragmentTransaction.commit();
onAttach
is not being called but only onCreateView
, which means that fragment was not-really re-attached.
Please advise how to make full detach/attach cycle. Thank you!
Upvotes: 0
Views: 47
Reputation: 38223
The original code is used to force onCreateView
(which may be useful at times).
onAttach
and onDetach
are called when the activity changes, so keep unrelated code out of these methods.
onCreate
is called only when the fragment is created (which is once for retained fragment, otherwise once for each configuration change) so keep unrelated code out.
If you need to do everything brand new you might as well instantiate a new fragment and replace the original one.
Upvotes: 1