I observe the strange behavior of the fragments. There are three fragments: A, B and C. Add A to activate. Inside A, create B and add it to A via childFragmentManager in A.onViewCreated. Then, by user action, we start the animation, which replaces fragment A with activation on fragment C. When you launch this transaction, B disappears first from a, and then the animation starts with what remains in A.

It looks like when you try to detach And first, all child fragments are detached, and only then the transaction starts. But! If B was not created programmatically, but described in layout A, then there is no such problem. A disappears along with B, as it should be

GitLab problem example: https://gitlab.com/restangel1993/fragmentinfragment

add or replace in a transaction — it doesn't matter, the problem remains. Like animation - I tried to give custom animations, use FramentTransition

The question arises: what is the difference between a fragment created programmatically and added through a transaction from a fragment created during an xml inflation? How not to let the B unhook from A ahead of time and screw up the animation?

  • I did not come across it myself, but it looks like the problem is old and basically all sorts of hacks were used, such as screenshots of a fragment, etc. But here they offer something sensible: stackoverflow.com/questions/46859132/… - Eugene Krivenja
  • The variant with the screen was also considered, but this is somehow not at all Camille ... Plus, the main question is still the reason for the difference in behavior. The fragment prescribed in xml does not require any crutches, what is the difference? I tried to understand the meaning of what is happening on your link ... it could)) Maybe I will come back and with a fresh head I will understand what is happening there - Dmitry Spitsko

0