Dana Course: started in Activity mode, and started in activity Mode
Activity Startup Mode
The Startup Mode of the Activity determines the number of Activity instances/objects.
By default, a new instance/object is created every time an Activity is activated.
Task Stack/rollback Stack
Records the order of activated activities in the same task, so that when you click the Back key on the device, the system can know which Activity to open to the foreground.
Stack pressure: when a new Activity is activated, the new Activity will execute the stack pressure by default. After the stack is pressed, the Activity will be at the top of the stack, that is, the Activity is displayed at the front end, other activities in the stack are placed in the background
Stack play: When the website Activity is destroyed, other activities in the stack will pop up. Colleagues who destroyed the Activity at the top of the original stack will get the top position of the stack for the Activity ranked 2nd.
[Configuration]
In AndroidManifest. mxl, configure the android: launchMode attribute for the node to configure the Startup Mode of Activiy.
[Start mode]
Standard: (default) standard mode. Every time an Activity is activated, a new instance/object will be created.
SingleTop: unique at the top of the stack. When the Activity is at the top of the stack, repeated activation does not create new instances, nor will the stack be pressed. Otherwise, when the Activity is not at the top of the stack, a new instance is created and the stack is pressed.
SingleTask: It is unique in the task stack. When no Activity exists in the task stack, a new instance is created and the stack is pressed. Otherwise, when the current Activity already exists in the task stack, no new instances will be created. All other activities that were originally above the Activity in the stack will be forced to play, so that the Activity to be activated will get the top position of the stack.
SingleInstance: The instance is unique. The Activity has only one instance at most. This Activity will forcibly occupy one new task stack, and there will be only one Activity in this stack.
Test SingleTop
The page is modified as follows:
......
After MainActivity is started
D/MainActivity: onCreate()D/MainActivity: onStart()D/MainActivity: onResume()
Click "Activate MainActivity". The hashCode on the page is not changed, indicating that the new Activity is not started.
D/MainActivity: onPause()D/MainActivity: onResume()
Now enable SecondActivity
D/MainActivity: onPause()D/SecondActivity: onCreate()D/SecondActivity: onStart()D/SecondActivity: onResume()D/MainActivity: onStop()
Then click Open MainActivity in Second and find that the hashCode is different from the first time you open MainActivity, so this is a new MainActivity.
D/SecondActivity: onPause()D/MainActivity: onCreate()D/MainActivity: onStart()D/MainActivity: onResume()D/SecondActivity: onStop()
Test singleTask
Modify the Startup Mode of the two activities as follows:
......
The MainActivity is enabled when the application is started, and the hashCode is 1136.
Then, Click Activate mainactivitytwice on the page.
Click "Activate SecondActivity1" to enable SecondActivity.
Click Activate MainActivity in SecondActivity, and then open MainActivity.
Click Activate MainActivity on the page
The task stack task is as follows:
In this case, enable SecondActivity in the MainActivity to display the hashCode of SecondActivity as 6536 on the page, which is the same as the one opened for the first time.
At this time, SecondActivity is displayed on the interface, so it should be at the top of the stack.
The two mainactivities that were previously on it have been destroyed.
Test singleInstance
Change SecondActivity to singleInstance
When you switch between MainActivity and SecondActivity, you will find that the switching animation has changed. This animation effect is the switching between the task and the task.
[Remarks]
When the Activity startup mode is configured as singleTask or singleInstance, the execution effect may be affected by the android: taskAffinity (kinship ).