Activitymanager is an important part of the Android framework that is responsible for the creation of a new activitythread process, the maintenance of the activity lifecycle, and the state switching of acitvity in the management system.
More on this side, please refer to Activitymanager.java, Activitymangaernative.java and Systemservcer.java files for more information.
The relationships of these several classes are as follows:
The relationship between several major classes of the Activitymanager framework is clearly described, and we do a lot of application development contact is actually the Activitymanager class, the class is also published in the SDK, the application can be directly accessed, It provides us with some basic methods of managing activity.
Public list<runningtaskinfo> getrunningtasks (int maxnum, int flags, Ithumbnailreceiver receiver) throws S Ecurityexception {try {return Activitymanagernative.getdefault (). Gettasks (Maxnum, flags, receiver); } catch (RemoteException e) {//System dead, we'll be dead too soon! return null; } }
These methods are not implemented, but instead call the Acitvitymanagernative Getdefault () method to return the object implementation.
/** * Retrieve the system ' s Default/global Activity manager. * /static public Iactivitymanager Getdefault () { return gdefault.get (); } private static final singleton<iactivitymanager> Gdefault = new singleton<iactivitymanager> () { Protected Iactivitymanager Create () { IBinder B = servicemanager.getservice ("activity"); if (false) { log.v ("Activitymanager", "default service binder =" + b); } Iactivitymanager am = asinterface (b); if (false) { log.v ("Activitymanager", "Default service =" + am); } return am; } ;
As seen from the code above, get the service with the name activity from ServiceManager. There's a word from acitvitymanagerservice.
Activitymanagerservice m = mself;
Servicemanager.addservice (Context.activity_service, M, true) while public static final String Activity_service = "ACTIVITY" ;
So IBinder B is actually activitymanagerservice.
However, the definition of asinterface in Activitymanagernative is as follows:
static public Iactivitymanager asinterface (IBinder obj) { if (obj = = null) { return null; } Iactivitymanager in = (Iactivitymanager) obj.querylocalinterface (descriptor); if (in = null) { return in; } return new Activitymanagerproxy (obj);
So from the above code it can be seen that these operations are dependent on the implementation of the Activitymanagerproxy proxy class, Iactivitmanager interface defines the operation of all Activitymanager framework, Activitymanagerproxy implements the interface Iactivitmanager, but does not really implement these methods, it is just a proxy class, the execution of the real action for the stub class Activitymanagerservice, The Activitymanagerservice object has only one coexistence in the system_process process, Activitymanagerservice inherits from the Activitymanagernative stub class.
From the previous analysis, Activitymanager exists in the user process, called by the user process to get some basic information about activity management, but the Activitymanager class does not really perform these operations, the actual execution of the operation in System_ Activitymanagerservice,activitymanagerservice is loaded as a service at system_process startup in the process, about how the Activitymanagerservice is loaded here is not a discussion, followed by the discussion of Android system startup, then from Activitymanager to Activitymanagerservice in the middle of a link, That is the process of communication, and Iactivitymanager and the implementation of the interface proxy class Activitymanagerproxy, stub class activitymanagernative is responsible for the role of process communication, Although there is no use of the Aidl file to define the process communication interface Iactivitymanager, in fact, we can think of it as a manual compilation of aidl process communication Java class implementation, Activitymanagerproxy is the proxy class, Activitymanagernative is a stub class, Iactivitymanager is Aidl interface, so it is easy to understand.
Understanding the basic structure of the Activitymanager framework above, it will be much easier to delve into it later.