Life cycle of Android Activity after pressing Back button

前端 未结 7 811
春和景丽
春和景丽 2020-12-07 19:17

I am little confused between the life cycle of two activities.

Suppose I have Activity A and Activity B.

B is called From A i.e A ----> B.

7条回答
  •  半阙折子戏
    2020-12-07 19:56

    The onDestroy method is called after back press. Then activity will be popped from the Activity back stack.

    From docs:

    If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.

    onDestroy() from docs:

    The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

    enter image description here

提交回复
热议问题