Fragment详解
add执行动作如下图:
detach执行动作如下图:
activity-destroy执行动作如下图:
remove执行动作如下图:
hide/show不执行生命周期,即他把fragment压入栈而已,作用:小项目可用hide/show来提高效率,大型项目需要考虑内存问题。。。
add->hide:
add->detach->hiden:
结论:hide/show不影响状态
add->detach->hiden->show:
同证如上结论;
add->hiden->show:
onhidenchanged()测试结果:只有hide和show会触发
replace执行动作如下图:
但replace后的fragment没有tag
详细清单如下:
fragment:
(fragment)The core series of lifecycle methods that are called to bring a fragment up to resumed state
(interacting with the user) are:
onAttach(Activity)called once the fragment is associated with its activity.
onCreate(Bundle)called to do initial creation of the fragment.
ViewGroup, Bundle)creates and returns the view hierarchy associated with the fragment.
onActivityCreated(Bundle)tells the fragment that its activityhas completed its ownActivity.onCreate().
onViewStateRestored(Bundle)tells the fragment that all of thesaved state of its view hierarchy has been restored.
onStart()makes the fragment visible to the user (based on its containing activity being started).
onResume()makes the fragment begin interacting with the user (based on its containing activitybeing resumed).
As a fragment is no longer being used, it goes through a reverse series of callbacks:
onPause()fragment is no longer interacting with the user either because its activity is beingpaused or a fragment operation is modifying it in the activity.
onStop()fragment is no longer visible to the user either because its activity is being stoppedor a fragment operation is modifying it in the activity.
onDestroyView()allows the fragment to clean up resources associated with its View.
onDestroy()called to do final cleanup of the fragment's state.
onDetach()called immediately prior to the fragment no longer being associated with its activity.
Back Stack,以后再说。
网友评论