onStop vs onDestroy

前端 未结 2 911
情深已故
情深已故 2021-02-20 01:26

I have tried to research exactly when the onDestroy method is called for an activity, but I\'ve read some confusing and conflicting information. In general, my question is: unde

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-20 02:24

    onDestroy() is called whenever:

    • The user takes out the activity from the "recent apps" screen.
    • The user takes out the activity from the "recent apps" screen.

    onStop() is called whenever:

    • The user leaves the current activity.

    So in your example, when the user launches Activity B, Activity A called onStop().

    EDIT: The onDestroy() method is not always being called, according to the documentation. onStop() is always called beginning with Honeycomb, so move code you explicitly need to do before the activity stops to there.

    Starting with Honeycomb, an application is not in the killable state until its onStop() has returned. https://developer.android.com/reference/android/app/Activity#ActivityLifecycle

    Hope this helped :D

提交回复
热议问题