系统中的活动作为活动堆栈进行管理。当一个新的activity启动时,它被放置在栈顶,成为正在运行的activity——前一个activity在栈中始终保持在它的下方,并且在新的activity退出之前不会再次回到前台。
一个活动基本上有四种状态:
**If an activity in the foreground of the screen (at the top of the stack), it is active or running.**
**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.**
**If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.**
**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.**
下图展示了一个Activity的重要状态路径。方形矩形表示您可以实现的回调方法,以便在 Activity 在状态之间移动时执行操作。彩色椭圆是 Activity 可以处于的主要状态。