Android series six (activity startup mode and lifecycle)

Source: Internet
Author: User

First, what is activity?

Simply put: Activity is an interactive interface that fills the window or hovers over other windows. In an application that is typically composed of multiple activity, a master activity is specified in the Manifest.xml, as set


<actionandroid:name= "Android.intent.action.MAIN"/>


When the program first runs, the user will see the activity, which can be manipulated by initiating other activity. This current activity will stop when other activity is started, and the new activity will be pushed into the stack and the user focus will be taken while the activity is being manipulated. All know that the stack is advanced after the principle, then when the user presses the back key, the current activity is destroyed, the previous activity resumed.


Second, activity life cycle

See:

Three, start mode

Android defines four loading modes for us: Standard, Singletop, Singletask, and SingleInstance.

In standard load mode, when a task request loads an activity, the task instantiates the activity directly and puts it on top of the stack, regardless of whether there is an instance of the activity in the previous stack.

When activity is set to the load mode of Singletop, when a task request loads an activity, if the stack top of the task's corresponding stack is an activity instance, then it is not recreated, but instead calls Onnewintent. If an instance of activity in the stack for that task exists, but not at the top, then the activity is still recreated. Simply put, the focus activity (current activity) can no longer activate an instance of itself. Activity in Singletop mode can be instantiated multiple times, but it is not possible to overlap multiple instances of the same activity.

Singletask load mode, when a task request loads an activity, it is not recreated if there is an instance of activity in the corresponding stack for that task. If it has already been instantiated, the activity instance on the task will be destroyed and called Onnewintent. In a word, activity in Singletask mode has only one instance in its own task and does not allow other activity to override itself on startup

In singleinstance this mode, when a task request loads an activity, if there is an instance of activity in the stack of all the tasks, it is not recreated. If there is not an instance of activity in the stack of all the tasks, then the instance of the activity is created and a new task is exclusive, and the other activity cannot exist in the task.


Android series six (activity startup mode and lifecycle)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.