美文网首页
ViewPager+Fragment 切换生命周期。

ViewPager+Fragment 切换生命周期。

作者: zsgnaw | 来源:发表于2017-07-13 00:33 被阅读67次

ViewPager默认缓存:
缓存当前Fragment左右各一个。
当黑屏或者home键时,缓存中的所有Fragment都会走一样的变化。

三个Fragment依次:OnePlaceholderFragment、TwoPlaceholderFragment、ThreePlaceholderFragment。

首次打开(生成OnePlaceholderFragment和TwoPlaceholderFragment):

OnePlaceholderFragment:
onCreate()--onCreateView()--onActivityCreated()--onStart()--onResume()
TwoPlaceholderFragment:
onCreate()--onCreateView()--onActivityCreated()--onStart()--onResume()
ThreePlaceholderFragment:
// 未生成

切换到TwoPlaceholderFragment(生成ThreePlaceholderFragment):

OnePlaceholderFragment:
// 无变化
TwoPlaceholderFragment:
// 无变化
ThreePlaceholderFragment:
onCreate()--onCreateView()--onActivityCreated()--onStart()--onResume()

切换到ThreePlaceholderFragment(移除OnePlaceholderFragment):

OnePlaceholderFragment:
// onPause()--onStop()--onDestroyView()
TwoPlaceholderFragment:
// 无变化
ThreePlaceholderFragment:
// 无变化

切回TwoPlaceholderFragment或者直接点击回到OnePlaceholderFragment:

OnePlaceholderFragment:
onCreateView()--onActivityCreated()--onStart()--onResume()
TwoPlaceholderFragment和ThreePlaceholderFragment按原规律变化

相关文章

网友评论

      本文标题:ViewPager+Fragment 切换生命周期。

      本文链接:https://www.haomeiwen.com/subject/gzvihxtx.html