Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

android - Fragment and parent activity life cycle together

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 little doubt about this. My question is

  1. If A Activity call B Activity through Intent but A does not call finish() method then A will be in Pause state if B is Transparent or SemiTransparent and in Stop state if B is Opaque. Am I right?
  2. If A Activity contains Fragment F then if A will go to Pause state then F will go to Pause state and if A will be in Stop state then F will be in Stop state too. Am I right?
  3. If A calls B Activity and B is Transparent then A will be in Pause state and F will too. If B call finish() then A will come to Resume state but what will happen to F? will it come to resume from pause? If it is then how and what steps because I have not seen any direct link in Fragment life cycle which indicates onPause() to onResume() directly as Activity can do.

    Hope I am able to ask what I want. Sorry for my bad Englsh.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...