网上有的博客写得太乱

不如自己翻译官方文档

Lifecycle

生命周期

Though a Fragment's lifecycle is tied to its owning activity, it has its own wrinkle on the standard activity lifecycle. It includes basic activity lifecycle methods such as onResume(), but also important are methods related to interactions with the activity and UI generation.

虽然Fragmentd的生命周期依赖于拥有它的Activity,但在Activity的生命周期标准上他有自己的一套周期,包括基本的activity生命周期方法,比如onResume(),这些方法也都与activity和ui相互交互。

The core series of lifecycle methods that are called to bring a fragment up to resumed state (interacting with the user) are:

将fragment从运行到resumed状态(与用户交互)的生命周期核心方法是:

1、onAttach(Activity) called once the fragment is associated with its activity.

一旦fragment与activity有联系调用此方法

2.onCreate(Bundle) called to do initial creation of the fragment.

fragment的初始化时调用

3、onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view hierarchy associated with the fragment

创建和返回和fragment有关的视图层级。

4.onActivityCreated(Bundle) tells the fragment that its activity has completed its own Activity.onCreate().

告诉fragment它关联的activity已经完成了自己的onCreate()方法

5,onViewStateRestored(Bundle) tells the fragment that all of the saved state of its view hierarchy has been restored.

告诉fragment所有的它的视图层级的状态已经存储

6,onStart() makes the fragment visible to the user (based on its containing activity being started).

fragment可见时调用

7,onResume() makes the fragment interacting with the user (based on its containing activity being resumed).

fragment可以和用户交互

As a fragment is no longer being used, it goes through a reverse series of callback:

当fragment不再使用时,经理一系列反向回调。

1,onPause() fragment is no longer interacting with the user either because its activity is being paused or a fragment operation is modifying it in the activity.

fragment不再与用户交互,要么因为它关联的activity进入pasused状态,要么因为这个activity正在修改fragment的操作。

2,onStop() fragment is no longer visible to the user either because its activity is being stopped or a fragment operation is modifying it in the activity.

fragment不再可见,要么因为它关联的activity正在进入stop状态,要么因为这个activity正在修改fragment的操作

3,onDestroyView() allows the fragment to clean up resources associated with its View.

运行fragment与它相关视图的资源

4,onDestroy() called to do final cleanup of the fragment's state.

清除fragment的状态。

5,onDetach() called immediately prior to the fragment no longer being associated with its activity

在Fragment不再和Activity关联之前调用onDetach()

Android官方文档翻译——Fragment生命周期的更多相关文章

  1. 【Android归纳】Fragment生命周期-基于实验的最新总结

    如今非常多应用的开发都是基于FragmentActivity中嵌套Fragment进行开发的,所以,假设我们可以清晰地知道他们的生命周期,那么会使我们的开发变的easy. 对于Activity的生命周 ...

  2. Android Activity与Fragment生命周期

  3. Android Activity与Fragment生命周期 对应关系

  4. Android Fragment 生命周期及其API使用(建议使用自定义View替换Fragment)

    我为什么不主张使用Fragment Fragment:( Fragment就相当于一个有生命周期的View,它的生命周期被所在的Activity的生命周期管理 ) 生命周期回调说明: onAttach ...

  5. Android Fragment 生命周期及其正确使用(建议使用自定义View替换Fragment)

    使用Fragment 官方例子中显示: 例如:一个学生Fragment,需要传入studentId,进行http请求显示,那么setArguments后防止杀掉Fragment后,参数为0,显示不了数 ...

  6. 重温Android和Fragment生命周期

    重温下Android和Fragment生命周期,理解生命周期方法的作用,什么时候调用,可以做一些什么操作. 1.Android生命周期 1.1 生命周期图 1.2 生命周期函数说明 onCreate: ...

  7. Android Activity生命周期以及Fragment生命周期的区别与分析

    Android Fragment生命周期图: Activity生命周期图: 对照图: Fragment生命周期分析: 1. 当一个fragment被创建的时候,它会经历以下状态. onAttach() ...

  8. Android零基础入门第86节:探究Fragment生命周期

    一个Activity可以同时组合多个Fragment,一个Fragment也可被多个Activity 复用.Fragment可以响应自己的输入事件,并拥有自己的生命周期,但它们的生命周期直接被其所属的 ...

  9. Android中Fragment生命周期和基本用法

    1.基本概念 1. Fragment是什么? Fragment是可以让你的app纵享丝滑的设计,如果你的app想在现在基础上性能大幅度提高,并且占用内存降低,同样的界面Activity占用内存比Fra ...

随机推荐

  1. 最短路径—Dijkstra 算法和Floyd 算法

    某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多.这让行人很困扰. 现在 ...

  2. Html Input disabled属性

    input的disabled: <input type="text" name="name" placeholder="请输入名称" ...

  3. 「POJ3237」Tree(树链剖分)

    题意 给棵n个点的树.边有边权然后有三种操作 1.CHANGE i v 将编号为i的边权变为v 2.NEGATE a b 将a到b的所有边权变为相反数. 3.QUERY a b 查询a b路径的最大边 ...

  4. [洛谷P2045]方格取数加强版

    题目大意:有一个n*n的矩阵,每个格子有一个非负整数,规定一个人从(1,1)开始,只能往右或下走,走到(n,n)为止,并把沿途的数取走,取走后数变为0.这个人共取n次,求取得的数的最大总和. 解题思路 ...

  5. shell中处理用户输入

    1.使用命令行参数 在shell执行的时候命令行中输入的所有参数可以赋值给一些特殊变量,这些变量成为位置变量参数. 包括: $0返回脚本名称.$1为第一个参数.$2为第二个参数 ...$9第九个参数 ...

  6. springMVC+request.session实现用户登录和访问权限控制

    用springmvc mybatis实现用户登录登出功能,使用session保持登录状态,并实现禁止未登录的用户访问.感谢谷歌资源,在这里做个学习记录加深自己的印象. 原文在我的https://my. ...

  7. 第五章,AsyncTask和ProgressBar的练习(Android)

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  8. hdoj-1164-Eddy&#39;s research I【分解质因数】

    Eddy's research I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  9. Shiro架构及其组件

    Shiro可以帮助我们完成:认证.授权.加密.会话管理.与Web集成.缓存等.这不就是我们想要的嘛,而且Shiro的API也是非常简单:其基本功能点如下图所示: Authentication:身份认证 ...

  10. Android 勤用RXJava compose操作符消除重复代码

    相信小伙伴在使用RXJava与Retrofit请求网络时,都有遇到过这样的场景,在IO线程请求网络解析数据,接着返回主线程setData.更新View试图,那么也肯定熟悉下面这几句代码: .subsc ...