大牛们,请教个Fragment生命周期的问题,我在程序中调用detach(),看日志,AFragment执行了onDestroyView(),但之后Fragment切换时候,我再调用attach() 时候看AFragment没有调用onCreateView(),只调用了onActivityCreated(),不知道为什么,我没把Fragment addToBackStack,和这个有关系么Fragment生命周期
解决方案 »
- android 视频播放器中onErrorListener()哪些情况下会触发
- 请教Android源码编译问题
- JAVA中在画布中绘制图像X轴镜像问题?
- Cache partition already in use. Changes will not persist!
- android中多个CheckBox(已超过整个屏幕)全选和反选问题
- 捕获点击dialog
- Failed to find style 'switch Style' in current theme
- android代码如何用命令把raw文件里的文件复制到system/app里面(已经root)
- android获取颜色值转换
- 菜鸟求助 环信 Unknown Source
- 请问多层Fragment重叠,如何让底层的Fragment不响应点击等事件?
- 多线程只能运行一次
fragment = fm.findFragmentById(R.id.enter_afragment);
ft.attach( fragment );
ft.detach(mCurrentFragment);
onCreateView()
The system calls this when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.这里面说到了一个the first time。第一次已经调用了这个方法,虽然你又调用了detach,他会调用
onDestroyView()
Called when the view hierarchy associated with the fragment is being removed.
然而你再调用attach()的时候,系统的GC还没有去回收,又或者你某个地方的引用还在系统GC不会去回收这个view,所以你再调用attach的时候,他已经不是the first time了,就不会调用OnCreateView了。这只是我个人看了文档之后的见解,有可能有误,仅供参考