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.





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