3 activity design framework 3.1 activity outside the feature space
Let's take a look at the activity in the external feature space that Android app developers are exposed to. For AMS, this activity is a customer service activity. When creating an Android Application, the app programmer builds the sub-class of the activity to display the feature space outside andoid. The following simple example describes how to create an activity.
Demoactivity extend Activity
{
Oncreate
Onresume
Onpause
Onstop
}
In the external feature space (SDK) of Android, Android application programmers do not know when the process starts and how the system messages are transmitted. How is this demoactivity instantiated? Which process is the activity hosted on? The analysis in this section provides the answer.
We can see from activitythread that all activities in the application process are placed in mactivities.
These activityrecord records the instances of the activity subclass created by the programmer in the application process, which is called the activity of the external feature space. These activity instances are placed on the application side for actual interaction. To manage these activities, the AMS kernel also has a shadow activity called historyrecord.
3.2 Relationship between activity and historyrecord
In the whole system, activity actually has two entities. An activity that deals with application programmers in an application process, and a history record with management functions in AMS. All activities in the application process are registered in the mactivity array of the activitythread instance, while at the Am end, the histroytrecord instance is placed in the mhistroy stack. The mhistory stack is the place where Android manages the activity. The activity that the user sees is placed on the top of the stack.
The relationship between activity and histrotyrecord can be expressed as follows:
The kernel entity of the activity depends on the member variables of processrecord. With processrecord, we can access all the activities that belong to the process. Processrecord records the connection with the application process: iactivtitythread interface. Through this interface, you can access the corresponding activity method. During the launch activity, AMS transmits the corresponding historyrecord as a token to the activity at the Customer Service end to establish a connection with the activity at the Customer Service end. When the activity status in AMS changes, the activity at the Customer Service end will be found through this contact, so that the message or action is transmitted to the interface facing the application: xxxactivity.
3.3 launch process of actvity
1) Initiate a request to startactivity (intent)
2) Activity Service Manager receives the request to execute the startactivity function.
Created: historyrecord instance R.
Add R to mhistory.
(3) through app. thread. schedulelaunchactvity (app, R) @ activitythread. Java
(4) Create a New activityrecord in the app.
(5) create a new activity object and put it in activityrecord.
(6) add activityrecord to mactivites @ activitythread
(7) initiate activity. oncreate (...), which is oncreate in your application xxxactivity.
3.4 Resume of activity
(1) When will the activity be resume?
(2) rusume Process
Through the study of this process, we will further understand the interaction process between AMS and the application process.
On the AMS side, the core function resume: resumetopactivitylocked @ activitymanagerservice is called when the resume condition is met.
Histroyrecord at the top of the current stack of XXX
1) window switching: Hide the window of the previous activity,
2) Update lrulist (lrulist is one of the basis for eliminating applications)
3) xxx. App. thread. scheduleresumeactivity (XXX,
Isnexttransitionforward ());
4) completeresumelocked
Setfocusedactivitylocked
Mfocusactivity = xxx // The focus actvitiy is switched.
WM. setfocusedapp (XXX,
Mwindowmanager.exe cuteapptransition ();
Mnoanimactivities. Clear ();
On the Application side:
(5) scheduleresumeactivity
Handleresumeactivity (ibinder token, Boolean clearhide, Boolean isforward ){
Activityrecord r = extends mresumeactivity (token, clearhide );
Activityrecord r = mactivities. Get (token );
R. activity. Invoke mresume ()
Performresume
The entire resume process is as follows: