Fragment的状态与回调

Fragment的状态
Fragment的回调

  下图源自官网。

安卓中Fragment的生命周期-LMLPHP

体验Fragment生命周期

public class RightFragment extends Fragment {
    public static final String TAG = "RightFragment";
    @Override
    public void onAttach(Context context){
        super.onAttach(context);
        Log.d(TAG, "onAttach");
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate");
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        Log.d(TAG, "onCreateView");
        View view = inflater.inflate(R.layout.fragment_right, container, false);
        return view;
    }
    @Override
    public void onStart(){
        super.onStart();
        Log.d(TAG, "onStart");
    }
    @Override
    public void onResume(){
        super.onResume();
        Log.d(TAG, "onResume");
    }
    @Override
    public void onPause(){
        super.onPause();
        Log.d(TAG, "onPause");
    }
    @Override
    public void onStop() {
        super.onStop();
        Log.d(TAG, "onStop");
    }
    @Override
    public void onDestroyView(){
        super.onDestroyView();
        Log.d(TAG, "onDestroyView");
    }
    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d(TAG, "onDestroy");
    }
    @Override
    public void onDetach(){
        super.onDetach();
        Log.d(TAG, "onDetach");
    }
}

安卓中Fragment的生命周期-LMLPHP

08-08 02:35