现在的位置: 首页 > 综合 > 正文

Android Liftcycle

2013年09月17日 ⁄ 综合 ⁄ 共 1427字 ⁄ 字号 评论关闭

As you'll learn in the following lessons, there are several situtations in which an activitytransitions between different states that are illustrated in figure 1. However, only three ofthese states can be static. That is, the activity can exist in one of
only three states for anextended period of time:

Resumed
In this state, the activity is in the foreground and the user can interact with it.(Also sometimes referred to as the "running" state.)
Paused
In this state, the activity is partially obscured by another activity—theother activity that's in the foreground is semi-transparent or doesn't cover the entire screen. Thepaused activity does not receive user input and cannot execute any code.
Stopped
In this state, the activity is completely hidden and not visible to the user; it isconsidered to be in the background. While stopped, the activity instance and all its stateinformation such as member variables is retained, but it cannot execute any code.

The other states (Created and Started) are transient and the system quickly moves from them tothe next state by calling the next lifecycle callback method. That is, after the system callsonCreate(), it quickly callsonStart(),
which is quickly followed by onResume().

Note: The system calls onDestroy()after it has already calledonPause() and
onStop() in all situations except one: when you callfinish() from within the
onCreate()method. In some cases, such as when your activity operates as a temporary decision maker tolaunch another activity, you might callfinish() from within
onCreate() to destroy the activity. In this case, the systemimmediately callsonDestroy() without calling any of the otherlifecycle methods.

抱歉!评论已关闭.