片段和家长的活性生命周期在一起 [英] Fragment and parent activity life cycle together

查看:134
本文介绍了片段和家长的活性生命周期在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下四个议题创建一个片段,的Handling的片段生命周期,的管理活动生命周期暂停和恢复的活动 。所以我在这个有点疑问。 我的问题是

  1. 如果A 活动 B键活动意图但A不叫完成()方法,那么A将在暂停状态,如果B 透明半透明停止如果状态B是不透明。我说得对?
  2. 如果A 活动包含片段 F那么,如果A将转到暂停状态,则F会去暂停状态,如果A将在停止状态,则F会在停止状态了。我说得对?
  3. 如果一个呼叫B 活动 B是透明那么A将在暂停状态和F也会。如果乙方呼叫完成()那么A会来恢复状态,但会发生到F是什么?将它来自暂停恢复?如果它是又如何因为什么步骤我还没有看到在片段有直接的联系生命周期指示的onPause() onResume()直接作为活动可以做的。

      

    希望我能问我想要什么。对不起,我的坏ENGLSH。

  4.   

解决方案
  1. 您无法确定,只有在onPause会叫上,如果B是半透明或部分可见我的理解是:

      

    暂停

         

    另一项活动是在前台和具有焦点,但是这   一个是仍然可见。即,另一个活动是可见的顶部   这一个,该活动是部分透明或不包括   整个屏幕。一个暂停的activity是完全活着(活动   对象保留在内存中,它保持所有的状态和成员   信息,并且保持附着到所述窗口管理器),但也可以是   在极其低内存情况下杀死由系统。

  2. 是的,你是对的:

      

    ,该活动的生命周期,其中所述片段直接住   影响片段的生命周期,使得每个生命周期   回调为活动导致了类似的回调为每个   分段。例如,当活动接收的onPause()中,每个   片段在活动收到的onPause()。

    然而,相反的是不正确的,这意味着如果一个片段收到的onStop,这并不能保证活动的的onStop将被调用。

  3. 我不太清楚你所说的你的最后一句话还是怎么,你已经测试了这个意思。根据该片段文件:

      

    公共无效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

  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.

解决方案

  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.

这篇关于片段和家长的活性生命周期在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆