Fragment生命周期
方法汇总(根据调用顺序排序)
onAttach(Fragment连接到它的父Activity时调用):
public void onAttach(Activity activity){
super.onAttach(activity);//获得父Activity的引用
}
onCreate(创建Fragment并初始化):
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
onCreateView(返回一个Fragment的UI):
public void onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_first,container,false);
}
onActivityCreate(Fragment和Activity都被调用后才被调用):
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
}
onStart():
onresume():
onPause():
onStop():
onDestroyView():
onDestroy():
onDetach():