Android Fragment的生命周期

xiaoxiao2021-02-27  368

public class MeFragment extends Fragment { private static final String TAG = "jojo"; // 首先要依附在Activity上 @Override public void onAttach(Context context) { Log.d(TAG, "onAttach: "); super.onAttach(context); } @Override public void onCreate(@Nullable Bundle savedInstanceState) { Log.d(TAG, "onCreate: "); super.onCreate(savedInstanceState); } // 第一次画UI的时候调用 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView: "); // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_me, container, false); } //当在onCreateView方法里面准备view 初始化了 @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { Log.d(TAG, "onActivityCreated: "); super.onActivityCreated(savedInstanceState); } @Override public void onStart() { Log.d(TAG, "onStart: "); super.onStart(); } @Override public void onResume() { Log.d(TAG, "onResume: "); super.onResume(); } @Override public void onPause() { Log.d(TAG, "onPause: "); super.onPause(); } @Override public void onStop() { Log.d(TAG, "onStop: "); super.onStop(); } @Override public void onDestroyView() { Log.d(TAG, "onDestroyView: "); super.onDestroyView(); } @Override public void onDestroy() { Log.d(TAG, "onDestroy: "); super.onDestroy(); } @Override public void onDetach() { Log.d(TAG, "onDetach: "); super.onDetach(); } } 05-04 06:22:33.313 3176-3176/? D/jojo: onAttach: 05-04 06:22:33.313 3176-3176/? D/jojo: onCreate: 05-04 06:22:33.313 3176-3176/? D/jojo: onCreateView: 05-04 06:22:33.314 3176-3176/? D/jojo: onActivityCreated: 05-04 06:22:33.314 3176-3176/? D/jojo: onStart: 05-04 06:22:33.314 3176-3176/? D/jojo: onResume: 05-04 06:23:00.533 3176-3176/? D/jojo: onPause: // 调换到其他Activity 05-04 06:23:00.534 3176-3176/? D/jojo: onStop: 05-04 06:23:00.534 3176-3176/? D/jojo: onDestroyView: 05-04 06:23:00.534 3176-3176/? D/jojo: onDestroy: 05-04 06:23:00.534 3176-3176/? D/jojo: onDetach: 05-04 06:23:10.189 3176-3176/? D/jojo: onAttach: // 调换回fragment 05-04 06:23:10.189 3176-3176/? D/jojo: onCreate: 05-04 06:23:10.189 3176-3176/? D/jojo: onCreateView: 05-04 06:23:10.191 3176-3176/? D/jojo: onActivityCreated: 05-04 06:23:10.191 3176-3176/? D/jojo: onStart: 05-04 06:23:10.191 3176-3176/? D/jojo: onResume:
转载请注明原文地址: https://www.6miu.com/read-3261.html

最新回复(0)