Fragment and parent activity life cycle together

前端 未结 2 1104
盖世英雄少女心
盖世英雄少女心 2020-12-10 07:01

I was following these four topics Creating a Fragment, Handling the Fragment Lifecycle , Managing the Activity Lifecycle and Pausing and Resuming an Activity. So I am in a l

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 07:25

    1. You can't be sure that only onPause will be called on A if B is SemiTransparent or partially visible as I understand it:

      Paused

      Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity is partially transparent or doesn't cover the entire screen. A paused activity is completely alive (the Activity object is retained 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 situations.

    2. Yes, you are right:

      The lifecycle of the activity in which the fragment lives directly affects the lifecycle of the fragment, such that each lifecycle callback for the activity results in a similar callback for each fragment. For example, when the activity receives onPause(), each fragment in the activity receives onPause().

      However, the opposite is not true, meaning that if a fragment receives onStop, that does not guarantee that the Activity's onStop will be called.

    3. I am not quite sure what you mean by your last sentence or how you have tested this. According to the Fragment documentation:

      public void onResume ()

      Called when the fragment is visible to the user and actively running. This is generally tied to Activity.onResume of the containing Activity's lifecycle

      It says generally because it depends on how the fragment is handled by the activity.

提交回复
热议问题