Help us understand the problem. What is going on with this article?

Activityのライフサイクル(ログ)

More than 3 years have passed since last update.

なんとなく、分かった気になっている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

u-16
おしごとうけたまわります
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした