What is the android activity lifecycle ? How an android create new activity?There are a lot articles about the android activity lifecycle, most of them are just talking about a legend process.And has not clarified the principle.Now we carefully analyze the android activity lifecycle.

The same as the other mobile phone platform applications, the Android application activity lifecycle is unified control, which means that the fate of the applications written is in the hands of the system, we can't change it, only learn and adapt to it.

It is easy to say :When our cellphone is running an application, maybe receive a phone call or a text message, or the cellphone is out of battery.Then the application will be interrupted to give priority to serve the basic functions of the principle, and the other system does not allow you to take up a lot of resources.To ensure the call feature of the cellphone at least, so when the lack of resources of the cellphone the application has been possible to be killed.

Look at the following picture

Android Activity Lifecycle

Android Activity Lifecycle

1. Method of starting Activity execution.

onCreate()-->onStart()-->onResume() Now the application is processing operation status.

onCreate: Create the interface and do some data initialization work.
onStart: This step becomes the user-visible non-interactive.
onResume: Become the user interactive.(Manage the top of Activity by the way of the stack in the activity stack system.Run to completion popped off the stack, and then return to the previous Activity.)

2.Method of ending Activity execution.

OnPause()-->OnStop()-->OnDestory() Now the application is destroyed.

OnPause: This step is user-visible but non-interactive, the system will stop the animation and other CPU-intensive things.Already know from the above description, save some of your data should be here,because now your application was reduced priority,may be recovered by the system. The saved data here should be read out in the onResume.Note: this method should do short time, because the next activity will start not waiting until the completion of this method .
OnStop: Become invisible, is covered by the next activity.
OnDestroy: This activity is the last method to be called before killed.Maybe the outside classes call the Finish() function or system in order to save space to kill it temporarily.You can judge using the isFinishing().

3.onPause()-->onResume Transforming principle.

Activity can regularly switch between the resumed and paused status, when activity is processing operation status, the new activity run to the front desk, and the original activity will be pushed onto the stack, the current activity is in the top of the stack.

4.Idle for a long time activity -> to a running state process.

onStop()-->onRestart()-->onStart()-->onResume()-->activity running

Note:In onPause, onStop, onDestroy three states activity are likely killed by the system as other applications need memory.But in the other states activity will not be ended.Now you may understand a little bit of the android activity lifecycle.



This address is http://www.computerites.com/programming-skills/2013/04/what-is-the-android-activity-lifecycle-719.html