Android Activity Lifecycle: onStart() -> onStop() possible?

后端 未结 3 1754
难免孤独
难免孤独 2021-02-03 13:36

In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method onResume() or

相关标签:
3条回答
  • 2021-02-03 14:04

    When the user leaves your activity, the system calls onStop() to stop the activity
    (1). If the user returns while the activity is stopped, the system calls onRestart()
    (2), quickly followed by onStart()
    (3) and onResume()
    (4). Notice that no matter what scenario causes the activity to stop, the system always calls onPause() before calling

    0 讨论(0)
  • 2021-02-03 14:12

    According to the flowchart on the page provided, it is not possible for onStop() to be called without onResume() being called. I could think of some potential scenario in which the system shuts down the application in the middle of starting it up, but I have no clue what or how such a scenario would be triggered, or if it even exists.

    As pointed out by Tseng, it's possible that a task will never be brought to the foreground (I'm thinking of say, the task that syncs the phone with an Exchange server). I imagine Such a task will never have onResume() or onPause() called.

    0 讨论(0)
  • 2021-02-03 14:22
    1. From your activity, start another activity that is not full-screen (for example give it android:theme="@android:style/Theme.Dialog").

      At this point your first activity has had onPause() called but not onStop() because it is not in the front but still visible.

    2. Press home.

      At this point onStop() is called for your first activity.

    3. Relaunch your app.

      At this point onStart() is called for your first activity, but not onResume() because it still has the non-full-screen activity on top of it.

    4. Press home.

      At this point onStop() is called on the first activity, without having gone through onResume().

    0 讨论(0)
提交回复
热议问题