核心代码:
package cn.zengfansheng.fragmentLifecycle;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
//为了更好的兼容前面的版本
public class FragmentLifecycle extends Fragment {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
System.out.println("1、onAttach()");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("2、onCreate()");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
System.out.println("3、onCreateView()");
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
System.out.println("4、onActivityCreated()");
}
@Override
public void onStart() {
super.onStart();
System.out.println("5、onStart()");
}
@Override
public void onResume() {
super.onResume();
System.out.println("6、onResume()");
}
@Override
public void onPause() {
super.onPause();
System.out.println("7、onPause()");
}
@Override
public void onStop() {
super.onStop();
System.out.println("8、onStop()");
}
@Override
public void onDestroyView() {
super.onDestroyView();
System.out.println("9、onDestroyView()");
}
@Override
public void onDestroy() {
super.onDestroy();
System.out.println("10、onDestroy()");
}
@Override
public void onDetach() {
super.onDetach();
System.out.println("11、onDetach()");
}
} |