Fragment与Activity交互

Activity直接影响它所包含的Fragment的生命周期,所以对Activity的某个生命周期方法的调用也会产生对Fragment相同方法的调用。例如:当activity的onPause()方法被调用时,它所包含的所有的fragment们的onPause()方法都会被调用。

Fragment比Activity还要多出几个生命周期回调方法,这些额外的方法是为了与activity的交互而设立的。

onAttach():当fragment和activity被关联时调用。

onCreateView():当创建fragment的UI被初始化时调用。

onActivityCreated():当activity的onCreate()方法返回时调用。

onDestroyView():当fragment的UI被移除的时候调用。

onDetach():当fragment和activity去关联时调用。

Android官网解释如下:

onAttach():Called when the fragment has beenassociated with the activity (the Activity is passed in here).

onCreateView():Called to create the view hierarchyassociated with the fragment.

onActivityCreated():Called when the activity'sonCreate() method has returned.

onDestroyView():Called when the view hierarchyassociated with the fragment is being removed.

onDetach():Called when the fragment is beingdisassociated from the activity.



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值