Android中Fragment的生命周期
在Android中的一個Activity中,通過以下方法加載Fragment。
ActionOpenDocumentFragment
從開始加載Fragment,然後螢幕鎖屏,然後再進入此界面,然後傳回退出。此過程中的生命周期執行方法如下圖所示:
上圖中中有多個以onAttach開頭的方法。onViewCreated,onSaveInstanceState方法不在官方的那張周期圖上。在onCreateView方法中引入xml布局檔案,可以在onViewCreated或者onActivityCreated中擷取各個子View。
例如:
在onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)中:
pdfPageView = view.findViewById(R.id. image);
在onActivityCreated(@Nullable Bundle savedInstanceState)中:
previousButton = getView().findViewById(R.id. previous);
螢幕豎屏切換為橫屏時,onStart(),onResume會被多次調用。