The life cycle of fragments and parent activity

I followed these four topics: Creating a fragment , Processing the fragment life cycle , “Managing the life cycle of an action,” and Pausing and resuming activity . Therefore, I doubt it a little. My question is:

  • If A Activity calls B Activity through Intent , but A does not call the finish() method, then A will be in the Pause state if B is Transparent or SemiTransparent and in Stop if B is Opaque . I'm right?
  • If A Activity contains Fragment F, then if A enters the Pause state, then F enters the Pause state, and if A is in the Stop state, then F will be in the Stop state too. I'm right?
  • If A calls B Activity , and B calls Transparent , then A will be in the Pause state, and F too. If B calls finish() , then A will go into Resume state, but what happens to F? will he come to resume the pause? If so, then how and what steps, because I did not see a direct connection in the Fragment life cycle that points onPause() to onResume() directly, how Activity can do.

    I hope I can ask what I want. Sorry for my bad Englsh.

+7
source share
2 answers
  • You cannot be sure that only onPause will be called on A if B is translucent or partially visible, as I understand it:

    Paused

    Another event is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this and this activity is partially transparent or does not cover the entire screen. The stopped activity is completely alive (the activity of the object is stored in memory, it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extremely low memory conditions.

  • Yes you are right:

    The life cycle of the activity in which the fragment lives directly affects the life cycle of the fragment, so that each life cycle of the callback for the activity leads to a similar callback for each fragment. For example, when an activity takes onPause (), each fragment in the activity receives onPause ().

    However, the opposite is not true, which means that if a fragment receives onStop, this does not guarantee that Activity onStop will be called.

  • I'm not quite sure what you mean by the last sentence or how you tested it. According to the Fragment documentation:

    public void onResume ()

    Called when a fragment is displayed to the user and is actively working. This is usually associated with an Activity.onResume containing the activity life cycle.

    He speaks generally, because it depends on how the fragment is processed using activity.

+3
source
  • If A invokes activity B through Intent, but A does not call the finish () method, then A will be paused if B is transparent or translucent and stopped if B is opaque. I'm right?

    Yes true

  • If A Activity contains Fragment F, then if A goes into Pause state, then F goes into pause state, and if A is in a stop state, then F will also be in a stop state. I'm right?

    Yes, right

  • If A calls activity B, and B is transparent, then A will be paused, and F too. If B ends the call (), then A will return to the resume state, but what will happen to F? will he come to resume the pause? If this is how and what steps, because I did not see a direct link in the fragmentation life cycle that points onPause () to onResume () directly, how Activity can do it.

What you understand is true, even in this scenario, the fragment will be moved from onPause to onResume in the same way as in the action. But, unfortunately, this is not in the Android developer. Perhaps this is due to the fact that they wanted to avoid complex diagrams that could create more confusion.

0
source

All Articles