Android 4.4 Stack structure changes

Source: Internet
Author: User

We know that the activity in the form of AMS is activityrecord,task in the form of AMS Taskrecord, the process AMS that management form Processrecord.

Let's look at the version number before 4.4:
android4.4 the previous version number, the AMS management Task is to manage all the activity through a ArrayList mhistory:


Conclusions such as the following:
(1) All Activityrecord will be stored in mhistory management;
(2) Each of the Activityrecord will be corresponding to a taskrecord, and have the same taskrecord
Activityrecord in the mhistory will be in a continuous position;
(3) The activity of the same taskrecord may be in separate processes, each activity
Process is not related to task;
(4) Taskrecord and Processrecord are not connected.


The management of the 4.4 version number has changed:

4.4


4.2


Can be found, 4.4 added a Activitystacksupervisor class to assist the management of Taskstack, see the source code:

/** the stack containing the Launcher app */private Activitystack mhomestack;/** the Non-home stack currently receiving in Put or launching the nextactivity. Ifhome is* in front then Mhomestack overrides mfocusedstack.* does not ACCESS directly-it May is null, use Getfocusedstack () */private Activitystack mfocusedstack;/** all the Non-launcher stacks */private arraylist<activitystack> Mstacks = new arraylist<activitystack> ();p rivate static final int stack_state_home_in_front = 0;private static fina l int stack_state_home_to_back = 1;private static final int stack_state_home_in_back = 2;private static final int Stack_st Ate_home_to_front = 3;private int mstackstate = Stack_state_home_in_front;

        From the gaze can be seen, in the Android4.4, do not use the original mhistory to manage all the activity, but at the level of management:
Only two stacks are included in the Activitystacksupervisor mstacks Mhomestack and Mfocusstack. Only the Launcher task is saved in the Mhomestack, and the other tasks are put into
The Mfocusstack. For Task operations, AMS uses Mstacksupervisor. For acitivity operation, AMS uses Activitystack.


Conclusions such as the following:
(1) The top of the management hierarchy is an array of type Activitystack mstacks, which is used to manage all activitystack.
(2) There are only two activitystack in the system, one is mhomestack for saving Launcher activity, and the other is Mfocusedstack, which is used to save the activity of the non-Launcher App.
PS: The survey found that the task management interface recent, long press home, will also be saved in Mhomestack.


(3) The mstacks array, only the two stacks above, but do not know why a List to manage the two elements.
(4) In each activitystack, can have more than one taskrecord. These taskrecord are stored in the activitystack.java:arraylist<taskrecord> mtaskhistory.
(5) in Taskrecord, including Arraylist<activityrecord> Mactivities, which holds information about all Activity in the task, including Activitystack Stack, Used to record which stack it belongs to, including int
Numactivities, used to record the number of Activity in the current Task.
(6) The above analysis shows that in order to find an activity, you need to find a hierarchy: Find the appropriate stack, then find the task in the stack, and then find the activity in the task.

It is important to note that:

void Removetask (Taskrecord Task) {mwindowmanager.removetask (task.taskid); final Activitystack stack = task.stack;final Activityrecord r = stack.mresumedactivity;if (r! = NULL && R.task = = Task) {stack.mresumedactivity = null;}  if (Stack.removetask (Task) &&!stack.ishomestack ()) {if (debug_stack) slog.i (TAG, "removetask:removing stack" + Stack), Mstacks.remove (stack), final int stackid = stack.mstackid;final int nextstackid = Mwindowmanager.removestack ( STACKID);//Todo:perhaps We need to let the Activitymanager determine the next focus...if (Mfocusedstack = null | | mfocu Sedstack.mstackid = = Stackid) {//If This was the last app stack, set Mfocusedstack to Null.mfocusedstack = Nextstackid = Home_stack_id? Null:getstack (Nextstackid);}}} Activitystack getlaststack () {switch (mstackstate) {case Stack_state_home_in_front:case Stack_state_home_to_back: return mhomestack;case stack_state_home_to_front:case STACK_STATE_HOME_IN_BACK:default:return mfocusedstack;}

        The source code seems to be switching back and forth in these two stacks, when switching to determine the next focusedstack, but the source code inside a gaze//todo:perhaps We need to let the Activitymanager determine T He next focus ... It's more incredible than that. It seems that detailed how to get the next focus is controlled in AMS.

Therefore, developers need to pay attention to using android:launchmode= "singleinstance" in 4.4 development.
Type of startup mode, because 4.4 under such a startup mode of scheduling and 4.2 differences (the reason should be in the Activitymanager, the detailed reasons are still in the investigation ...) If you want to use it, be sure to test it.





Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Android 4.4 Stack structure changes

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.