1. 自定义lifecycleoffragment布局文件
  2. 在main_activity布局中引用自定义的fragment布局
  3. 到logcat中查看程勋运行的结果
  4. 代码如下:

    自定义的fragment布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="这是展示LifeCycleOfFragment,请到logcat中查看"
android:textColor="#000000"
android:textSize="25sp"
/>

</LinearLayout>

Fragment的java类

package com.cm.lifecycleoffragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by Administrator on 2016/1/2.
*/
public class LifeCycleOfFragment extends Fragment{ @Override
public void onAttach(Activity activity) {
super.onAttach(activity); Log.d("lifecycleoffragment","onAttach()");
} @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); Log.d("lifecycleoffragment","onCreate()");
} @Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d("lifecycleoffragment","onCreateView()");
return inflater.inflate(R.layout.lifecycleof_fragment,container,false); } @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.d("lifecycleoffragment", "onActivityCreated()");
} @Override
public void onStart() {
super.onStart();
Log.d("lifecycleoffragment", "onStart()");
} @Override
public void onResume() {
super.onResume();
Log.d("lifecycleoffragment", "onResume()");
} @Override
public void onPause() {
super.onPause();
Log.d("lifecycleoffragment", "onPause()");
} @Override
public void onStop() {
super.onStop();
Log.d("lifecycleoffragment", "onStop()");
} @Override
public void onDestroyView() {
super.onDestroyView(); Log.d("lifecycleoffragment", "onDestroyView()");
} @Override
public void onDestroy() {
super.onDestroy();
Log.d("lifecycleoffragment", "onDestroy()");
} @Override
public void onDetach() {
super.onDetach(); Log.d("lifecycleoffragment", "onDetach()");
} }

在main_activity的布局文件中引用fragment

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
> <fragment
android:name="com.cm.lifecycleoffragment.LifeCycleOfFragment"
android:id="@+id/lifecycleof_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/> </RelativeLayout>

Logcat打印的程序运行过程:

按home键返回的运行过程:

再次进入程序的运行过程:

按ctrl+f11程序的运行过程:

按back键的运行过程:

以上过程充分展示fragment的生命周期。

最新文章

  1. Unity3D 学习——入门资料整理
  2. Linux IPC System V 共享内存
  3. Duilib 实现窗口点击关闭确认退出提示
  4. Python.resource-for-python-from-internet
  5. c++ 设计模式4 (Strategy)
  6. C#判断奇偶数的函數
  7. Visual C#使用DirectX实现视频播放
  8. md5sum.c, md5.c, md5.h
  9. bzDemo
  10. Spotlights
  11. ASP.NET MVC 5使用Swagger生成API文档
  12. FineReport性能调优的一些办法
  13. 聊聊Unity2018的LWRP和混合光照
  14. Linux中目录以及路径问题
  15. python之生成器和列表推导式
  16. 2019南昌邀请赛网络预选赛 J.Distance on the tree(树链剖分)
  17. Linux命令行下:把程序放后台执行,以及从后台继续执行程序
  18. [Laravel] 15 - REST API: sidebar with unit test
  19. 20165225《Java程序设计》第三周学习总结
  20. javascript 点击按钮实现隐藏显示切换效果

热门文章

  1. VB关闭其他进程的输入法
  2. react+redux完整项目
  3. 用struts实现简单的登录
  4. CentOS7 安装MongoDB 3.0服务器
  5. pdf预览-js版本
  6. java 的 sqlHelper,改改之后也适用于不使用 EF 的 C# 项目,包含查询和建表。
  7. PHP PDO函数库详解
  8. iOS时间问题
  9. 微信 URL Scheme详细参数
  10. Android 组件属性