Lifecycle -Activity

Activity is an application component, which a user can interact with the screen provided to perform make calls, take pictures, send e-mail or view a map and other operations. Activity Each window will receive a drawing for its user interface. 

Window usually fill the screen, but can also be smaller than the screen and float on top of other windows.
Activity typically use a plurality of loosely connected to one another. Generally designated in the application as an Activity "main" Activity, Activity that is presented to the user when you first start the application. 

And each Activity can start another Activity, in order to perform different operations. Each time a new Activity starts, the previous Activity will stop, but the system will be in the stack ( "return stack") to retain the Activity.

Activity When a new start, the system will be pushed to return to the stack, and to obtain user focus. Return stack follow the basic "last in, first out 'stack mechanism, therefore, when the user completes the current Activity and press the" return "button, the system will eject it from the stack (and destroyed), and then restore the previous Activity.
When a new Activity Activity due to a start and stop, the system will notify the state change through the life cycle callback method of the Activity. 

Activity due to the change of state - is to create a system Activity, stop the Activity, Activity recovery or destruction Activity- callback method and received may be several, each callback will provide the opportunity to perform with the corresponding changes in the state of a specific operation for you.

For example, when you stop, your Activity should release any large objects, such as network or database connection. When Activity is restored, you can re-acquire the resources needed to execute the interrupt and resume operations. These state transitions are part of the Activity lifecycle.
onCreate () to create a 
call when you first create Activity.
This method performs all the normal static set up - create views, bind data to lists, and so on. This method of delivery system to a Bundle object, which comprises the Activity of a state, but at least the capture state.
Then after onStart always ().

Not after the termination.
onRestart () to restart

In the activity has stopped and is about to start for the first time before calling again. Then after onStart always () does not terminate after the fact.
onStart () to start 
the upcoming calls before visible to the user.
If the activity to the foreground, then followed onResume (), if the activity become hidden, then followed onStop ().
It can not be terminated afterwards.
onResume () recovery 

in activity, the activity is about to begin Called before interaction with the user. 

Always followed onPause (). 

It can not be terminated afterwards.
onPause () to pause 

the system is commonly used to confirm unsaved changes to persistent data, stop animations and other content may consume CPU, and so on. It should perform the desired operation very quickly, because after it returns, the next activity to continue. 

If the activity is returned foreground, then followed onResume (), if the active turn invisible to the user state, followed by onStop (). 

Afterwards be terminated.
onStop () stops 

if the activity is destroyed or another Activity (a new or existing Activity Activity) continues into its coverage, this situation may occur. 

If Activity resume interaction with the user, then followed onRestart (), if Activity is destroyed, then followed onDestroy (). 

Afterwards be terminated.
onDestroy () destroyed 

when the end of the event (the event was a call to finish ()), or a system to save space temporarily destroy the activity, activity instance, might call it. These two cases can be distinguished by isFinishing () method. 

Afterwards be terminated.
Summary of 

an Activity onCreate normal start -> onStart -> onResume 

a normal exit Activity (return key to fall back to the desktop) onPause -> onStop -> onDestroy 

start with normal start again
Activity has been in the foreground 

Jump to another Activity before 

the current Activity execution onPause -> onStop 

fall back to the current Activity execution onRestart -> onStart -> onResume
Activity press the home button return to the desktop onPause -> onStop 

back again onRestart -> the onStart -> onResume 

Activity home button to return to the desktop inoperable after onPause -> onStop 

(eg: put the screen, the other open Activity), or application He was forced to kill the 

back again Activity onCreate - onStart -> onResume
Dialog box when there is impact on the life cycle of the 

common dialog does not have any impact on the life cycle 

will be another Activity is designed to display dialog boxes by android: theme = "@ style / Theme.AppCompat.Dialog" 

Startup dialog box, the current implementation of Activity onPause 

dialog operation is finished, return to the current Activity execution onResume

Guess you like

Origin www.cnblogs.com/oldkeyset/p/12123613.html