/**
* Called when the activity is starting. This iswhere most initialization
* should go: calling {@link #setContentView(int)} to inflate the
* activity's UI, using {@link #findViewById} to programmatically interact
* with widgets inthe UI, calling
* {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve
* cursors for data being displayed, etc.
*
* <p>You can call {@link #finish} from within this function, in
* which case onDestroy() will be immediately called without any oftherest
* ofthe activity lifecycle ({@link #onStart}, {@link #onResume},
* {@link #onPause}, etc) executing.
*
* <p><em>Derived classes must call throughtothe super class's
* implementation of this method. If they do not, an exception will be
* thrown.</em></p>
*
* @param savedInstanceState If the activity is being re-initialized after
* previously being shut down then this Bundle containsthe data it most
* recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b>
*
* @see #onStart
* @see #onSaveInstanceState
* @see #onRestoreInstanceState
* @see #onPostCreate
*/
onRestart
/**
* Called after {@link #onStop} when the current activity is being
* re-displayed tothe user (the user has navigated backtoit). It will
* be followed by {@link #onStart} and then {@link #onResume}.
*
* <p>For activities that are using raw {@link Cursor} objects (instead of
* creating them through
* {@link #managedQuery(android.net.Uri , String[], String, String[], String)},
* this is usually the place
* wherethe cursor should be requeried (because you had deactivated itin
* {@link #onStop}.
*
* <p><em>Derived classes must call throughtothe super class's
* implementation of this method. If they do not, an exception will be
* thrown.</em></p>
*
* @see #onStop
* @see #onStart
* @see #onResume
*/
onStart
/**
* Called after {@link#onCreate} — or after {@link #onRestart} when
* the activity had been stopped, but is now again being displayed to the
* user. It will be followed by {@link#onResume}.
*
* <p><em>Derived classes must call through to the superclass's
* implementation ofthis method. If they donot, an exception will be
* thrown.</em></p>
*
* @see#onCreate
* @see#onStop
* @see#onResume
*/
onRestoreInstanceState
/**
* This method is called after {@link#onStart} when the activity is
* being re-initialized from a previously saved state, given here in
* <var>savedInstanceState</var>. Most implementations will simply use {@link#onCreate}
* to restore their state, but it is sometimes convenient to do it here
* after all of the initialization has been done or to allow subclasses to
* decide whether to use your default implementation. The default
* implementation ofthis method performs a restore of any view state that
* had previously been frozen by {@link#onSaveInstanceState}.
*
* <p>This method is called between {@link#onStart} and
* {@link#onPostCreate}.
*
* @param savedInstanceState the data most recently supplied in {@link#onSaveInstanceState}.
*
* @see#onCreate
* @see#onPostCreate
* @see#onResume
* @see#onSaveInstanceState
*/
onResume
/**
* Called after {@link #onRestoreInstanceState}, {@link #onRestart}, or
* {@link #onPause}, for your activity to start interacting with the user.
* This is a good place to begin animations, open exclusive-access devices
* (such asthe camera), etc.
*
* <p>Keep in mind that onResume isnotthe best indicator that your activity
* is visible tothe user; a system window such asthe keyguard may be in
* front. Use {@link #onWindowFocusChanged} to know for certain that your
* activity is visible tothe user (for example, to resume a game).
*
* <p><em>Derived classes must call throughtothe super class's
* implementation of this method. If they do not, an exception will be
* thrown.</em></p>
*
* @see #onRestoreInstanceState
* @see #onRestart
* @see #onPostResume
* @see #onPause
*/
onPause
/**
* Called as part ofthe activity lifecycle when an activity is going into
* the background, but has not (yet) been killed. The counterpart to
* {@link #onResume}.
*
* <p>When activity B is launched infrontof activity A, this callback will
* be invoked on A. B will not be created until A's {@link #onPause} returns,
* so be sure tonot do anything lengthy here.
*
* <p>This callback is mostly used for saving any persistent state the
* activity is editing, to present a "edit in place" model tothe user and
* making sure nothing is lost if there are not enough resources to start
* the new activity withoutfirst killing this one. This is also a good
* place to do things like stop animations and other things that consume a
* noticeable amount of CPU in order to make the switch tothe next activity
* as fast as possible, orto close resources that are exclusive access
* such asthe camera.
*
* <p>In situations wherethe system needs more memory it may kill paused
* processes to reclaim resources. Because of this, you should be sure
* that all of your state is saved bythetime you returnfrom
* this function. In general {@link #onSaveInstanceState} is used to save
* per-instance state inthe activity and this method is used to store
* global persistent data (in content providers, files, etc.)
*
* <p>After receiving this call you will usually receive a following call
* to {@link #onStop} (after the next activity has been resumed and
* displayed), however insome cases there will be a direct call backto
* {@link #onResume} without going through the stopped state.
*
* <p><em>Derived classes must call throughtothe super class's
* implementation of this method. If they do not, an exception will be
* thrown.</em></p>
*
* @see #onResume
* @see #onSaveInstanceState
* @see #onStop
*/
onSaveInstanceState
/**
* Called to retrieve per-instance state from an activity before being killed
* so thatthe state can be restored in {@link #onCreate} or
* {@link #onRestoreInstanceState} (the {@link Bundle} populated by this method
* will be passed to both).
*
* <p>This method is called before an activity may be killed so that when it
* comes backsometimeinthe future it can restore its state. For example,
* if activity B is launched infrontof activity A, andatsome point activity
* A is killed to reclaim resources, activity A will have a chance to save the
* current state ofits user interface via this method so that when the user
* returns to activity A, the state ofthe user interface can be restored
* via {@link #onCreate} or {@link #onRestoreInstanceState}.
*
* <p>Do not confuse this method with activity lifecycle callbacks such as
* {@link #onPause}, which is always called when an activity is being placed
* inthe background oronits way to destruction, or {@link #onStop} which
* is called before destruction. One example of when {@link #onPause} and
* {@link #onStop} is called and not this method is when a user navigates back
* from activity B to activity A: there is no need to call {@link #onSaveInstanceState}
* on B because that particular instance will never be restored, so the
* system avoids calling it. An example when {@link #onPause} is called and
* not {@link #onSaveInstanceState} is when activity B is launched in front of activity A:
* the system may avoid calling {@link #onSaveInstanceState} on activity A if it isn't
* killed during the lifetime of B sincethe state ofthe user interface of
* A will stay intact.
*
* <p>The default implementation takes care of most ofthe UI per-instance
* state for you by calling {@link android.view.View#onSaveInstanceState()} on each
* view inthe hierarchy that has an id, andby saving theidofthe currently
* focused view (all of which is restored bythe default implementation of
* {@link #onRestoreInstanceState}). If you override this method to save additional
* information not captured by each individual view, you will likely want to
* call throughtothe default implementation, otherwise be prepared to save
* all ofthe state of each view yourself.
*
* <p>If called, this method will occur before {@link #onStop}. There are
* no guarantees about whether it will occur beforeorafter {@link #onPause}.
*
* @param outState Bundle in which to place your saved state.
*
* @see #onCreate
* @see #onRestoreInstanceState
* @see #onPause
*/
onStop
/**
* Called when you are no longer visible tothe user. You will next
* receive either {@link #onRestart}, {@link #onDestroy}, or nothing,
* depending on later user activity.
*
* <p>Note that this method may never be called, in low memory situations
* wherethe system doesnot have enough memory to keep your activity's
* process runningafterits {@link #onPause} method is called.
*
* <p><em>Derived classes must call throughtothe super class's
* implementation of this method. If they do not, an exception will be
* thrown.</em></p>
*
* @see #onRestart
* @see #onResume
* @see #onSaveInstanceState
* @see #onDestroy
*/
onDestroy
/**
* Perform any final cleanup before an activity is destroyed. This can
* happen either because the activity is finishing (someone called
* {@link #finish} on it, or because the system is temporarily destroying
* this instance ofthe activity to save space. You can distinguish
* between these two scenarios withthe {@link #isFinishing} method.
*
* <p><em>Note: do notcounton this method being called as a place for
* saving data! For example, if an activity is editing data in a content
* provider, those edits should be committed in either {@link #onPause} or
* {@link #onSaveInstanceState}, not here.</em> This method is usually implemented to
* free resources like threads that are associated with an activity, so
* that a destroyed activity doesnot leave such things aroundwhilethe
* restofitsapplicationis still running. There are situations where
* the system will simply kill the activity's hosting process without
* calling this method (or any others) init, so it should not be used to
* do things that are intended to remain aroundafterthe process goes
* away.
*
* <p><em>Derived classes must call throughtothe super class's
* implementation of this method. If they do not, an exception will be
* thrown.</em></p>
*
* @see #onPause
* @see #onStop
* @see #finish
* @see #isFinishing
*/
上一篇(http://blog.csdn.net/niuzhucedenglu/article/details/50910369)通过覆写Activity的方法来查看Activity的生命周期,这里对上一篇进行补充一下,看官方文档怎么说的^_^onCreate/** * Called when the activity is starting. This is where most