Can some draw lifecycle of Fragment and its parent

2020-02-24 04:25发布

问题:

In Android docs, I found a specs on Activity lifecycle and on Fragment lifecycle individually, but never together. It does not seem obvious as I attached a debugger to FragmentActivity which hosts my fragment, and the life cycle is more than crazy. It looks like activity finishes first and then fragments starts, which is impossible.

Fragment's lifecycle


Activity's lifecycle


Logically, fragment should "jump into" activity's lifecycle after its onResume and it would end before activity's onPause, but it seems it is not happening.

Can someone either show me the lifecycle of the fragment in connection to its parent's activity or direct me to some good tutorial on this?

回答1:

Have you seen this? Fragment is created after Activity is created. It doesn't seem possible for "activity finishes first and then fragments starts" Can you post the code for that?
This is what I tested, 1 FragmentActivity , two Fragments :