Fragment研究前后

研究下应用启动堆叠的方式:
other activity启动方式,Intent 使用
Intent i = new Intent(this, MainActivity.class);  
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


Fragment:
1. 当一个fragment被创建的时候,它会经历以下状态.。
onAttach()
onCreate()
onCreateView()
onActivityCreated()
2. 当这个fragment对用户可见的时候,它会经历以下状态。
onStart()
onResume()
3. 当这个fragment进入“后台模式”的时候,它会经历以下状态。
onPause()
onStop()
4. 当这个fragment被销毁了(或者持有它的activity被销毁了),它会经历以下状态。
onPause()
onStop()
onDestroyView()
onDestroy() // 本来漏掉类这个回调,感谢xiangxue336提出。
onDetach()
5. 就像activitie一样,在以下的状态中,可以使用Bundle对象保存一个fragment的对象。
onCreate()
onCreateView()
onActivityCreated()
6. fragments的大部分状态都和activitie很相似,但fragment有一些新的状态。
onAttached() —— 当fragment和activity关联之后,调用这个方法。
onCreateView() —— 创建fragment中的视图的时候,调用这个方法。
onActivityCreated() —— 当activity的onCreate()方法被返回之后,调用这个方法。
onDestroyView() —— 当fragment中的视图被移除的时候,调用这个方法。
onDetach() —— 当fragment和activity分离的时候,调用这个方法。

7.整体思路

onAttach(Activity) called once the fragment is associated with its activity.

onCreate(Bundle) called to do initial creation of the fragment.

onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view hierarchy associated with the fragment.

onActivityCreated(Bundle) tells the fragment that its activity has completed its own Activity.onCreate().

onViewStateRestored(Bundle) tells the fragment that all of the saved 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 interacting with the user (based on its containing activity being 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 being paused 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 stopped or 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.





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章