Fragment 生命周期+replace+add+addToBackStack+remove


replace

第二个fragment replace 第一个fragment。第一Fragment 调用 onDestroyView ,onDestroy和onDetach。


06-13 12:38:43.22029702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onAttach:com.example.leeco.myfragmenttest.MainActivity@cf15fe4

06-13 12:38:43.22029702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onCreate: null

06-13 12:38:43.22029702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onCreateView:

06-13 12:38:43.22129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onActivityCreated:null

06-13 12:38:43.22129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onStart:

06-13 12:38:43.22729702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onResume:

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onAttach:com.example.leeco.myfragmenttest.MainActivity@cf15fe4

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onCreate: null

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onPause:

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onStop:

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onDestroyView:

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onDestroy:

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onDetach:

06-13 12:38:51.31129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onCreateView:

06-13 12:38:51.31429702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onActivityCreated:null

06-13 12:38:51.31429702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onStart:

06-13 12:38:51.31429702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onResume:

 

replace + addToBackStack

第一个Fragment调用onDestroyView,不会调用onDestroy和onDetach


06-13 12:50:24.34429702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onAttach:com.example.leeco.myfragmenttest.MainActivity@1fe2399

06-13 12:50:24.34429702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onCreate: null

06-13 12:50:24.34429702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onCreateView:

06-13 12:50:24.34829702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onActivityCreated:null

06-13 12:50:24.34829702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onStart:

06-13 12:50:24.36429702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onResume:

06-13 12:50:27.77829702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onAttach:com.example.leeco.myfragmenttest.MainActivity@1fe2399

06-13 12:50:27.77829702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onCreate: null

06-13 12:50:27.77929702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onPause:

06-13 12:50:27.77929702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onStop:

06-13 12:50:27.77929702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onDestroyView:

06-13 12:50:27.78029702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onCreateView:

06-13 12:50:27.78229702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onActivityCreated:null

06-13 12:50:27.78229702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onStart:

06-13 12:50:27.78229702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onResume:

06-13 12:50:38.56129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onPause:

06-13 12:50:38.56129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onStop:

06-13 12:50:38.56229702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onDestroyView:

06-13 12:50:38.56229702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onDestroy:

06-13 12:50:38.56229702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onDetach:

06-13 12:50:38.56329702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onCreateView:

06-13 12:50:38.56429702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onActivityCreated:null

06-13 12:50:38.56429702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onStart:

06-13 12:50:38.56429702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onResume:

06-13 12:50:40.16929702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onPause:

                                                                              

                                                                              [ 06-13 12:50:40.191  1530: 2144D/         ]

                                                                              HostConnection::get() New Host Connection established 0x7ffed6daed00,tid 2144

06-13 12:50:41.46629702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onStop:

06-13 12:50:41.46629702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onDestroyView:

06-13 12:50:41.46729702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onDestroy:

06-13 12:50:41.46729702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onDetach:

 

add

对第一个Fragment没有影响,两个同时存在。


06-13 12:48:08.02929702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onAttach:com.example.leeco.myfragmenttest.MainActivity@4f4d706

06-13 12:48:08.02929702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onCreate: null

06-13 12:48:08.03029702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onCreateView:

06-13 12:48:08.03129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onActivityCreated:null

06-13 12:48:08.03129702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onStart:

06-13 12:48:08.06329702-29702/com.example.leeco.myfragmenttest I/FragmentOne: onResume:

06-13 12:48:13.86529702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onAttach:com.example.leeco.myfragmenttest.MainActivity@4f4d706

06-13 12:48:13.86529702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onCreate: null

06-13 12:48:13.86529702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onCreateView:

06-13 12:48:13.88129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onActivityCreated:null

06-13 12:48:13.88129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onStart:

06-13 12:48:13.88129702-29702/com.example.leeco.myfragmenttest I/FragmentTwo: onResume:


remove

 remove当前Fragment会调用onDestroyView。

06-13 13:36:52.98920740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onAttach:com.example.leeco.myfragmenttest.MainActivity@de93ed9

06-13 13:36:52.98920740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onCreate: null

06-13 13:36:52.98920740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onCreateView:

06-13 13:36:52.99120740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onActivityCreated:null

06-13 13:36:52.99120740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onStart:

06-13 13:36:52.99120740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onResume:

06-13 13:36:59.52620740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onPause:

06-13 13:36:59.52720740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onStop:

06-13 13:36:59.52720740-20740/com.example.leeco.myfragmenttest I/FragmentOne: onDestroyView:

 

remove+add

remove 第一个Fragment 和add第二个Fragemnt,第一个会调用onDestroyView。 

06-13 13:40:37.34131025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onAttach:com.example.leeco.myfragmenttest.MainActivity@cb9825f

06-13 13:40:37.34131025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onCreate: null

06-13 13:40:37.34131025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onCreateView:

06-13 13:40:37.34431025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onActivityCreated:null

06-13 13:40:37.34431025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onStart:

06-13 13:40:37.38331025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onResume:

06-13 13:40:45.43431025-31025/com.example.leeco.myfragmenttest I/FragmentTwo: onAttach:com.example.leeco.myfragmenttest.MainActivity@cb9825f

06-13 13:40:45.43431025-31025/com.example.leeco.myfragmenttest I/FragmentTwo: onCreate: null

06-13 13:40:45.44331025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onPause:

06-13 13:40:45.44331025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onStop:

06-13 13:40:45.44331025-31025/com.example.leeco.myfragmenttest I/FragmentOne: onDestroyView:

06-13 13:40:45.44831025-31025/com.example.leeco.myfragmenttest I/FragmentTwo: onCreateView:

06-13 13:40:45.45231025-31025/com.example.leeco.myfragmenttest I/FragmentTwo: onActivityCreated:null

06-13 13:40:45.45231025-31025/com.example.leeco.myfragmenttest I/FragmentTwo: onStart:

06-13 13:40:45.45331025-31025/com.example.leeco.myfragmenttest I/FragmentTwo: onResume:



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值