Transfer from http://blog.csdn.net/linghu_java/article/details/17266603
Every interface in Android is an activity, and switching interface operations is actually an instantiation of multiple different activity. The startup mode of activity in Android determines how the activity starts running.
The startup mode of Android total activity is divided into four types:
Activity startup Mode setting: <activity android:name= ". Mainactivity "android:launchmode=" standard "/>activity four types of startup mode: 1. Standard default startup mode, The activity is created each time the activity is activated and placed in the task stack. 2. Singletop If there is an instance of the activity at the top of the task, reusing the instance will create a new instance and put it into the top of the stack (even if the activity instance already exists on the stack, as long as it is not on top of the stack, an instance will be created). 3. Singletask If an instance of the activity is already in the stack, the instance is reused (Onnewintent () of the instance is invoked). When reused, the instance is returned to the top of the stack, so the instances above it will be removed from the stack. If the instance does not exist in the stack, a new instance is created to be put into the stack. 4. SingleInstance creates the activity instance in a new stack and lets multiple apps share the activity instance in the stack. Once an instance of the activity in the schema is present on a stack, any application that activates the activity will reuse the instance in that stack, with the effect of sharing an app with multiple applications, regardless of who activates the activity into the same application.
When you encounter an app's activity for multiple calls to start, multiple calls want only one instance of activity to exist, which requires the activity's onnewintent (Intent Intent) method. As long as you add your own onnewintent (intent) implementation in the activity plus the manifest in the activity settings lanuchmode= "Singletask".
Onnewintent () is very useful, when the activity first starts execution OnCreate ()---->onstart ()---->onresume () and other subsequent life cycle functions, It is also said that the first activation activity will not be performed to Onnewintent (). And then, if you want to start the activity again, that's the execution of Onnewintent ()---->onresart ()------>onstart ()----->onresume (). If the Android system releases the existing activity due to insufficient memory, the activity is restarted when it is called again (oncreate)---->onstart ()---->onresume (), and so on.
When calling to Onnewintent (intent), you need to use setintent (intent) in Onnewintent () to assign the intent to the activity. Otherwise, the subsequent getintent () is to get old intent.
Four boot modes and onnewintent () for the transfer activity