What methods are invoked in the Activity Lifecycle in the following cases:

前端 未结 4 1232
夕颜
夕颜 2020-12-13 11:15

Let\'s say I have a Hello World single Activity application. I start this application.

What methods are invoked in each case:

  • Home button is pressed:
4条回答
  •  情书的邮戳
    2020-12-13 11:41

    both pressing home button and receiving a call don't remove the activity from the task's stack, and will be available when you re-enter the app => onPause() => onStop().

    as the activity lifecycle diagram shows, re-entering the app calls => onRestart() => onStart() => onResume()

    pressing the back button instead kills the activity => onPause() => onStop() => onDestroy()

    re-entering the app in this case calls the classics => onCreate() => onStart() => onResume()

    EDIT

    from http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

    If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.

提交回复
热议问题