android - Fragment生命周期的管理问题
PHP中文网
PHP中文网 2017-04-17 13:18:52
0
3
414

Fragment的使用过程中,比较头疼的就是View hierarchy的变化。
Fragment有这么几种操作方式

增加到FragmentManager中:

  1. add
  2. attach
  3. show

从FragmentManager中移除

  1. remove
  2. detach
  3. hide

还有一个特殊的replace(实质就是remove老的, add新的)

这时候我把Fragment从Activity中隐藏,过一段时间再重新显示
比如先detach,再attach
那么只有在使用hide show的情况下 onCreateView 不会被重新调用。

因为onCreateView 和数据初始化息息相关,我想知道各位大神都是怎么管理Fragment的生命周期的呢?

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
洪涛

You can refer to Android Support V4: FragmentPagerAdapter and FragmentStatePagerAdapter

Please refer to: Difference between FragmentPagerAdapter and FragmentStatePagerAdapter

阿神

Try to only add it once. After the first Add, only use hide and show...
Anyway, this is what I did...

迷茫

@Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); }
I sometimes do some operations in this overloaded method to return whether the current fragment is visible

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!