相关图片请点击:详情点击
生命周期分五种常见的情况:
1. fragment第一次加载的时候即,FragmentTransaction.show();
**注:当hide()和show()进行切换的时候,该fragment的生命周期并没有什么变化**
09-15 22:48:14.298 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onAttach******
09-15 22:48:14.298 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onCreate
09-15 22:48:14.298 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onCreateView
09-15 22:48:14.301 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onActivityCreated
09-15 22:48:14.303 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onStart
09-15 22:48:14.308 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onResume
2.锁屏和解锁过程
- 锁屏状态
09-15 22:48:45.803 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onPause
09-15 22:48:45.817 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onStop
- 解锁状态
09-15 22:50:59.456 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onStart
09-15 22:50:59.468 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onResume
3.跳转到另一个Activity,重新回到该Activity
- 跳转到另一个Activity
09-15 22:54:04.092 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onPause
09-15 22:54:04.682 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onStop
- 从另一个Activity回来
09-15 22:54:19.711 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onStart
09-15 22:54:19.711 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onResume
4.回到主屏幕(按下HOME)和返回到该界面
- 回到主屏幕
09-15 22:56:49.570 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onPause
09-15 22:56:49.971 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onStop
- 回到该界面
09-15 22:57:01.098 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onStart
09-15 22:57:01.099 17888-17888/com.lyp.idcard I/TAG﹕ IDCardFragment****onResume
5.退出应用
09-15 23:00:08.713 25008-25008/com.lyp.idcard I/TAG﹕ IDCardFragment****onPause
09-15 23:00:09.015 25008-25008/com.lyp.idcard I/TAG﹕ IDCardFragment****onStop
09-15 23:00:09.015 25008-25008/com.lyp.idcard I/TAG﹕ IDCardFragment****onDestroyView
09-15 23:00:09.016 25008-25008/com.lyp.idcard I/TAG﹕ IDCardFragment****onDestroy
09-15 23:00:09.016 25008-25008/com.lyp.idcard I/TAG﹕ IDCardFragment****onDetach
示例代码:
public class IDCardFragment extends Fragment {
public static IDCardFragment newInstance(){
IDCardFragment fragment = new IDCardFragment();
return fragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Log.i("TAG","IDCardFragment****onAttach******");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("TAG", "IDCardFragment****onCreate");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i("TAG","IDCardFragment****onCreateView");
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_idcard_layout, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.i("TAG", "IDCardFragment****onActivityCreated");
}
@Override
public void onStart() {
super.onStart();
Log.i("TAG", "IDCardFragment****onStart");
}
@Override
public void onResume() {
super.onResume();
Log.i("TAG", "IDCardFragment****onResume");
}
@Override
public void onPause() {
super.onPause();
Log.i("TAG", "IDCardFragment****onPause");
}
@Override
public void onStop() {
super.onStop();
Log.i("TAG", "IDCardFragment****onStop");
}
@Override
public void onDestroyView() {
super.onDestroyView();
Log.i("TAG", "IDCardFragment****onDestroyView");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i("TAG", "IDCardFragment****onDestroy");
}
@Override
public void onDetach() {
super.onDetach();
Log.i("TAG", "IDCardFragment****onDetach");
}
}