なんとなく、分かった気になっているActivityのライフサイクル。
関わっている案件で、結構シビアに見ないといけないことになったので、ログ取ってみました。
@calciolife さんの記事に詳しいことは書かれています。
http://qiita.com/calciolife/items/39b2696a9a03e8591d40
この記事は単なるログを貼り付けただけです。
lauchMode変えたり、AppcompatActivityにしてみたり、他にも漏れてるコールバックがあればとか、随時追加していく予定。
設定とか
検証端末はNexus5
OSは4.4.4
U_16_main : 遷移元のActivity
U_16_sub : 遷移先のActivity
U_16_fragment : Activityにadd(replace)されるfragment
U_16_View : ActivityにaddされるView
Activityは2つともActionBarActivity
launchModeはSingleTop
FragmentはsupportFragmentを使用
ViewはFrameLayoutにTextViewを一個入れたもの
以下ログ
Activity立ち上げ
D/U_16_main﹕ onContentChanged D/U_16_main﹕ oncreate D/U_16_main﹕ onStart D/U_16_main﹕ onPostCreate D/U_16_main﹕ onResume D/U_16_main﹕ onResumeFragments D/U_16_main﹕ onPostResume D/U_16_main﹕ onAttachedToWindow
Activity遷移
D/U_16_main﹕ onUserInteraction D/U_16_main﹕ onUserInteraction D/U_16_main﹕ onUserLeaveHint D/U_16_main﹕ onPause D/U_16_sub﹕ onContentChanged D/U_16_sub﹕ onCreate D/U_16_sub﹕ onStart D/U_16_sub﹕ onPostCreate D/U_16_sub﹕ onResume D/U_16_sub﹕ onResumeFragments D/U_16_sub﹕ onPostResume D/U_16_sub﹕ onAttachedToWindow D/U_16_main﹕ onSaveInstanceState D/U_16_main﹕ onStop
Backkeyで戻る
D/U_16_sub﹕ onUserInteraction D/U_16_sub﹕ onKeyDown D/U_16_sub﹕ onUserInteraction D/U_16_sub﹕ onBackPressed D/U_16_sub﹕ onPause D/U_16_main﹕ onRestart D/U_16_main﹕ onStart D/U_16_main﹕ onResume D/U_16_main﹕ onResumeFragments D/U_16_main﹕ onPostResume D/U_16_sub﹕ onStop D/U_16_sub﹕ onDestroy
履歴ボタン/HomeButton/他のアプリへ遷移
D/U_16_main﹕ onUserInteraction D/U_16_main﹕ onUserLeaveHint --------- beginning of /dev/log/system D/U_16_main﹕ onPause D/U_16_main﹕ onSaveInstanceState D/U_16_main﹕ onStop
スリープモードにする
D/U_16_main﹕ onPause D/U_16_main﹕ onSaveInstanceState D/U_16_main﹕ onStop
履歴から復帰
D/U_16_main﹕ onRestart D/U_16_main﹕ onStart D/U_16_main﹕ onResume D/U_16_main﹕ onResumeFragments D/U_16_main﹕ onPostResume
Fragment をonCreateで追加
D/U_16_main﹕ onUserInteraction D/U_16_fragment﹕ onAttach D/U_16_main﹕ onAttachFragment D/U_16_fragment﹕ onCreate D/U_16_fragment﹕ onCreateView D/U_16_fragment﹕ onViewCreated D/U_16_fragment﹕ onActivityCreated D/U_16_fragment﹕ onViewStateRestored D/U_16_fragment﹕ onStart D/U_16_fragment﹕ onResume
Fragmentがある場合の back → fore
D/U_16_main﹕ onUserInteraction D/U_16_main﹕ onUserLeaveHint D/U_16_fragment﹕ onPause D/U_16_main﹕ onPause D/U_16_main﹕ onSaveInstanceState D/U_16_main﹕ onStop D/U_16_main﹕ onRestart D/U_16_fragment﹕ onStart D/U_16_main﹕ onStart D/U_16_main﹕ onResume D/U_16_fragment﹕ onResume D/U_16_main﹕ onResumeFragments D/U_16_main﹕ onPostResume
Fragmentがある場合の画面回転
D/U_16_fragment﹕ onPause D/U_16_main﹕ onPause D/U_16_main﹕ onSaveInstanceState D/U_16_main﹕ onStop D/U_16_fragment﹕ onDestroyView D/U_16_fragment﹕ onDestroy D/U_16_fragment﹕ onDetach D/U_16_main﹕ onDestroy D/U_16_fragment﹕ onAttach D/U_16_main﹕ onAttachFragment D/U_16_fragment﹕ onCreate D/U_16_main﹕ oncreate D/U_16_fragment﹕ onCreateView D/U_16_fragment﹕ onViewCreated D/U_16_fragment﹕ onActivityCreated D/U_16_fragment﹕ onViewStateRestored D/U_16_fragment﹕ onStart D/U_16_main﹕ onStart D/U_16_main﹕ onRestoreInstanceState D/U_16_main﹕ onPostCreate D/U_16_main﹕ onResume D/U_16_fragment﹕ onResume D/U_16_main﹕ onResumeFragments D/U_16_main﹕ onPostResume D/U_16_main﹕ onAttachedToWindow
onCreateにaddFragment + addViewを入れた場合のログ
D/U_16_main﹕ onContentChanged D/U_16_main﹕ oncreate D/U_16_fragment﹕ onAttach D/U_16_main﹕ onAttachFragment D/U_16_fragment﹕ onCreate D/U_16_fragment﹕ onCreateView D/U_16_fragment﹕ onViewCreated D/U_16_fragment﹕ onActivityCreated D/U_16_fragment﹕ onViewStateRestored D/U_16_fragment﹕ onStart D/U_16_main﹕ onStart D/U_16_main﹕ onPostCreate D/U_16_main﹕ onResume D/U_16_fragment﹕ onResume D/U_16_main﹕ onResumeFragments D/U_16_main﹕ onPostResume D/U_16_main﹕ onAttachedToWindow D/U_16_View﹕ onAttachedToWindow D/U_16_View﹕ onMeasure D/U_16_View﹕ onMeasure D/U_16_View﹕ onSizeChanged D/U_16_View﹕ onLayout D/U_16_View﹕ onMeasure D/U_16_View﹕ onMeasure D/U_16_View﹕ onLayout
fragment + view + Menu有りの場合
D/U_16_main﹕ oncreate D/U_16_main﹕ onContentChanged D/U_16_fragment﹕ onAttach D/U_16_main﹕ onAttachFragment D/U_16_fragment﹕ onCreate D/U_16_fragment﹕ onCreateView D/U_16_fragment﹕ onViewCreated D/U_16_fragment﹕ onActivityCreated D/U_16_fragment﹕ onViewStateRestored D/U_16_fragment﹕ onStart D/U_16_main﹕ onStart D/U_16_main﹕ onPostCreate D/U_16_main﹕ onResume D/U_16_fragment﹕ onResume D/U_16_main﹕ onResumeFragments D/U_16_main﹕ onPostResume D/U_16_main﹕ onAttachedToWindow D/U_16_View﹕ onAttachedToWindow D/U_16_View﹕ onMeasure D/U_16_View﹕ onMeasure D/U_16_View﹕ onSizeChanged D/U_16_View﹕ onLayout D/U_16_main﹕ onCreateOptionsMenu D/U_16_main﹕ onPrepareOptionsMenu D/U_16_View﹕ onMeasure D/U_16_View﹕ onMeasure D/U_16_View﹕ onLayout