回顾知识,发现问题!
看了很多网上关于fragment的讲解教程,发现很多都少了onViewStateRestored()这个周期,在此补充。
参考:http://www.android-doc.com/reference/android/app/Fragment.html#Lifecycle,做如下翻译,不足忘回馈。
onAttach(Activity) :
called once the fragment is associated with its activity.
调用该方法,将fragment与activity相关联
onCreate(Bundle) :
called to do initial creation of the fragment.
调用该方法,将fragment初始化;
onCreateView(LayoutInflater, ViewGroup, Bundle) :
creates and returns the view hierarchy associated with the fragment.
调用该方法,创建视图,返回结果View;
onActivityCreated(Bundle):
tells the fragment that its activity has completed its own Activity.onCreate().
调用该方法,通知fragment,activity中的oncreate()方法已完成;
onViewStateRestored(Bundle):
tells the fragment that all of the saved state of its view hierarchy has been restored.
调用该方法,通知fragment,该视图层已保存;
onStart():
makes the fragment visible to the user (based on its containing activity being started).
调用该方法,和activity的started方法相关联,将fragment展示给用户;
onResume():
makes the fragment interacting with the user (based on its containing activity being resumed).
调用该方法,和activity的resumed方法相关联,使fragment与用户交互;
As a fragment is no longer being used, it goes through a reverse series of callbacks:
调用以下的方法,fragment将不再被使用;
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.
调用该方法,fragment不与用户进行交互,此时activity的paused方法被调用,或者fragment正在被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.
调用该方法,fragment不再展示,此时activity的stopped方法被调用,或者fragment正在被activity修改;
onDestroyView():
allows the fragment to clean up resources associated with its View.
调用该方法,fragment清除掉资源与该activity的关联;
onDestroy() :
called to do final cleanup of the fragment's state.
调用该方法,清除fragment的状态;
onDetach():
called immediately prior to the fragment no longer being associated with its activity.
调用该方法,清除fragment与该activity的关联;