片段和家长的活性生命周期在一起 [英] Fragment and parent activity life cycle together
问题描述
我在以下四个议题创建一个片段,的Handling的片段生命周期,的管理活动生命周期和暂停和恢复的活动 。所以我在这个有点疑问。 我的问题是
- 如果A
活动
B键活动
到意图
但A不叫完成()
方法,那么A将在暂停
状态,如果B透明
或半透明
和停止
如果状态B是不透明
。我说得对? - 如果A
活动
包含片段
F那么,如果A将转到暂停
状态,则F会去暂停
状态,如果A将在停止
状态,则F会在停止
状态了。我说得对? - 如果一个呼叫B
活动
B是透明
那么A将在暂停
状态和F也会。如果乙方呼叫完成()
那么A会来恢复
状态,但会发生到F是什么?将它来自暂停恢复?如果它是又如何因为什么步骤我还没有看到在片段有直接的联系
生命周期指示的onPause()
到onResume()
直接作为活动可以做的。希望我能问我想要什么。对不起,我的坏ENGLSH。
-
您无法确定,只有在onPause会叫上,如果B是半透明或部分可见我的理解是:
暂停
另一项活动是在前台和具有焦点,但是这 一个是仍然可见。即,另一个活动是可见的顶部 这一个,该活动是部分透明或不包括 整个屏幕。一个暂停的activity是完全活着(活动 对象保留在内存中,它保持所有的状态和成员 信息,并且保持附着到所述窗口管理器),但也可以是 在极其低内存情况下杀死由系统。
-
是的,你是对的:
,该活动的生命周期,其中所述片段直接住 影响片段的生命周期,使得每个生命周期 回调为活动导致了类似的回调为每个 分段。例如,当活动接收的onPause()中,每个 片段在活动收到的onPause()。
然而,相反的是不正确的,这意味着如果一个片段收到的onStop,这并不能保证活动的的onStop将被调用。
-
我不太清楚你所说的你的最后一句话还是怎么,你已经测试了这个意思。根据该片段文件:
公共无效onResume()
当的片段是对用户可见被叫 积极运行。这通常依赖于的Activity.onResume 包含活动的整个生命周期。
它一般说,因为它取决于该片段是通过活动来处理。
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
- If A
Activity
call BActivity
throughIntent
but A does not callfinish()
method then A will be inPause
state if B isTransparent
orSemiTransparent
and inStop
state if B isOpaque
. Am I right? - If A
Activity
containsFragment
F then if A will go toPause
state then F will go toPause
state and if A will be inStop
state then F will be inStop
state too. Am I right? - If A calls B
Activity
and B isTransparent
then A will be inPause
state and F will too. If B callfinish()
then A will come toResume
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 inFragment
life cycle which indicatesonPause()
toonResume()
directly as Activity can do.Hope I am able to ask what I want. Sorry for my bad Englsh.
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.
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.
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.
这篇关于片段和家长的活性生命周期在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!