Learning AmS for some time, summary, or comb their ideas. Soldier, in some places does not understand, you can discuss with each other, exchange makes progress~~~
AmS can be said to be one of the most core module Android upper system life cycle process, as well as its main management application process of Activity, Service, Broadcast and Provider etc.
From the system point of view, AmS can be divided into Client and Service terminal: Client server is running on the app process, The app process to achieve a specific Activity, Service, Tell the system I have those Activity, Service, And the system call interface to complete the display; Service server is running on the SystemServer process, The concrete realization of system level ActivityManagerService, The system calls the Client request response, And the management of Client end of each app process life cycle.
Fig. 1 AmS diagram
Such as the above basic AmS class diagram, At Client end, We usually contact Application, Service and Activity are a subclass of Context, Context understood as environment, Context, It can tell the system the operation of Activity, The case of Service, Display the View, Do the chores. Context is a abstract class, The definition of the concrete realization method in ContextImpl, ContextWrapper Context as a decoration, The inside of the member variable mBase to ContextImpl, Of course this is not necessarily performed ContextImpl, As long as the successor to the Context, The inside interface, Can instantiate a mBase object.
We have also noted that we call a lot of Android interface, Must be passed to the Context object, We usually directly to a Activity object is passed as a parameter, If the methods defined inside the global variables or static variables, Cause long-term occupation of mContext reference, This will cause the Activity object cannot be JVM recovery, This such references are occupied, It may lead to OOM. We note that the Application is inherited from the Context, So the Application is Context, We know that Application created at the start of an application, Context &mdash so our app has been the existence of global Application object; &mdash, Then we take a call to the method Context object references in the global number of known can pass the Application object to avoid the above mentioned OOM.
The IActivityManager interface defines the app access to the AmS interface, is the main application requests the AmS to complete certain operations, such as starting a startup, finish Activity, stop Service, a. ActivityManagerService realized the interface defined in IActivityManager, This can be said to be the core of AmS, All AmS specific work basically are in the class or the class of control, The ActivityManagerService instance initialization in the process SystemServer has just started. The IApplicationThread interface defines the AmS can access the app interface, In response to the AmS through the interface control of APP processes and finish app, ApplicationThread is the concrete implementation of the IApplicationThread interface, An instance of ApplicationThread is initialized to create ActivityThread object in the app process starts when, The ActivityThread member variable mAppThread is the ApplicationThread object. In order to achieve cross process calls, ActivityManagerProxy and ApplicationThreadProxy respectively, the IActivityManager and IApplicationThread interfaces, as their agent for client and server use.
AmS is also used as a system service, through the ActivityManager defines some excuse for the use of app, ActivityManager to access AmS interface is realized by ApplicationThreadProxy.
The main data structure diagram is inside the AmS, see the code believe everyone will know these classes is stem what of, just here to summarize.
Figure 2 AmS internal data structure diagram
Posted by Broderick at April 12, 2014 - 8:47 PM
https://www.programering.com/a/MzNyIjMwATU.html