Fragment生命周期

本文详细介绍了Android开发中Fragment从创建到销毁的整个生命周期过程,包括onAttach、onCreate、onCreateView等关键方法的作用及调用顺序。

方法汇总(根据调用顺序排序)

 

onAttach(Fragment连接到它的父Activity时调用):

  public void onAttach(Activity activity){

    super.onAttach(activity);//获得父Activity的引用

  }

 

onCreate(创建Fragment并初始化): 

  public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);

  }

 

onCreateView(返回一个Fragment的UI):

  public void onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){

    return inflater.inflate(R.layout.fragment_first,container,false);

  }

 

onActivityCreate(Fragment和Activity都被调用后才被调用):

  public void onActivityCreated(Bundle savedInstanceState){

    super.onActivityCreated(savedInstanceState);

  }

 

onStart():

 

onresume():

 

onPause():

 

onStop():

 

onDestroyView():

 

onDestroy():

 

onDetach():

转载于:https://www.cnblogs.com/sunshinewxz/p/4729239.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值