Android's activity task stack

Source: Internet
Author: User

Activity of the task stack and startup mode, see a variety of websites and books or feel not its law. So the internet found an adb command:

  

    ADB shell Dumpsys activity activities

This statement lists the task stacks that exist in the phone.

1, clear all background tasks, run a self-written test application, found that the structure of the task stack is as follows:

    

Stack #1: Task ID # AboutAffinity=Package Name Activities=[XXX] Task ID # theAffinity=Package Name Activities=[Xxx]stack #0: Task ID #1Affinity=Com.huawei.android.launcher Activities=[[activityrecord{3d2a088 u0 Com.huawei.android.launcher/.unihome. Unihomelauncher T1}]
Task ID #3
Affinity=com.android.systemui
Activities=[activityrecord{e8167f6 u0 com.android.systemui/.recents. recentsactivity T3}]


The so-called task stack in Android actually has two layers: the task stack contains task,task containing activity.


Then modify the activity's startup mode for testing (self-test, do not know whether the different phones will have different results):
1, affinity is the value that we use android:taskaffinity set. Different tasks can be duplicated, for example, when we use the SingleInstance startup mode, the activity alone accounts for a task,task affinity that may be consistent with other activitiy-initiated tasks in the same process. But the ID of the task is inconsistent.
2, Launchmode is the default, the activity will run in the task that launches it, regardless of whether the two activity is the same application.
3, Launchmode for singleinstance, whether it is the same application, will be a separate task, and only one activity,
4, Launchmode is Singletask, the corresponding task will be found according to Affinity, does not exist the new, there is a switch to the task. Then see if there are any instances of the activity, then clear the above display, no new.

Personal Understanding:
1, stack only two, one is the system of launcher occupy, one is the application that we start occupy. Clicking the Home button is actually the two stack alternates.
2, each activity has a affinity, the default will be the package name of the application.
3, start an activity, first there is a current task, and then depending on the startup mode, choose whether to add the current task, or to find a new task.
4, Standard: new instance. The current task can be added. For example, if the activity in the current task is singleinstance, the corresponding task will be added according to Affinity.
Singletop: The same steps as standard to find the task that can be added, and then see if the activity at the top is the activity to start.
Singletask: Find the task that can be added by affinity and see if there is an activity instance in the task that you want to start.
SingleInstance: Based on affinity, if there is a task that has only the instance of activity to start, switch to that task.

The main task stack of the organization has a new understanding.

Android's activity task stack

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.