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

前端 未结 4 1216
夕颜
夕颜 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:43

    There can be several scenarios

    1. Opening the app from the app icon. following methods are called

      onCreate()-->onStart()-->onResume()

    2. When user presses the home button

      onPause()-->onStop()

    3. When user returns to the app from the Activity Stack

      onRestart()-->onStart()--> onResume()

    4. When the app is running and user presses the power button

      onPause()-->onStop()

    5. When user unlocks the phone

      onRestart()-->onStart()--> onResume()

    6. When user gets an incoming call while you are in the app

      onPause()

    7. When user returns to the app after disconnecting the phone call

      onResume()

    8. When user presses the back button from the app

      onPause()-->onStop()-->onDestroy()

    9. And when the user presses the home button and from the activity stack user swipes the app.onDestroy() method may or may not be called depending upon the OS contains the context of the Activity or not according to memory requirements

提交回复
热议问题