http://www.jianshu.com/p/6037f6fda285
What is Zygote? What's the effect?
Zygote means "fertilized egg".
Inside the Android system, Zygote is the name of a process. Android is based on the Linux system, and when your phone is powered on, the Linux kernel loads and starts a process called "Init". In the Linux system, all processes are forked out by the Init process, and our zygote process is no exception.
So when the first zygote process in the system is running, then opening the app after that is the equivalent of opening a new process. In order to achieve resource sharing and faster start-up, the way the Android system opens a new process is achieved by fork in the first zygote process. So, in addition to the first zygote process, other applications are in the process of zygote sub-process, so you understand why this process is called "fertilized eggs" it? Because it is like a fertilized egg, it can split quickly and produce the same kind of genetic material as a cell!
What is Systemserver? What's the effect? What is its relationship with zygote?
Systemserver is also a process, and is forked out by the zygote process.
Important services in the system are opened in this process, such as
Activitymanagerservice, Packagemanagerservice, Windowmanagerservice, etc.
Public Final classSystemserver {//main entrance of Zygote Public Static voidMain (string[] args) {NewSystemserver (). run (); } PublicSystemserver () {//Check for Factory test mode.Mfactorytestmode =Factorytest.getmode (); } Private voidrun () {... ignore some code ...//load the Local System service library and initialize itSystem.loadlibrary ("Android_servers"); Nativeinit (); //creating a System contextCreatesystemcontext (); //initializing the Systemservicemanager object, the following system service is required to invoke Systemservicemanager.startservice (class<t>), which initiates the corresponding service by reflection Msystemservicemanager =NewSystemservicemanager (Msystemcontext); //Open Service Try{startbootstrapservices (); Startcoreservices (); Startotherservices (); } Catch(Throwable ex) {SLOG.E ("System", "******************************************"); SLOG.E ("System", "************ Failure starting system Services", ex); Throwex; } ... ignore some code ...} //initializes the system context object Msystemcontext, and sets the default theme, Msystemcontext is actually a Contextimpl object. When Activitythread.systemmain () is called, Activitythread.attach (true) is called, and in Attach () the Application object is created. and called the Application.oncreate (). Private voidCreatesystemcontext () {activitythread Activitythread=Activitythread.systemmain (); Msystemcontext=Activitythread.getsystemcontext (); Msystemcontext.settheme (Android. R.style.theme_devicedefault_light_darkactionbar); } //Several core services are opened here, because these services depend on each other and are therefore placed in this method. Private voidstartbootstrapservices () {... ignore some code ...//Initialize ActivitymanagerserviceMactivitymanagerservice =Msystemservicemanager.startservice (activitymanagerservice.lifecycle.class). GetService (); Mactivitymanagerservice.setsystemservicemanager (Msystemservicemanager); //Initialize the Powermanagerservice because other services need to rely on this service and therefore need to be initialized as soon as possibleMpowermanagerservice = Msystemservicemanager.startservice (powermanagerservice.class); //Power Management is now turned on, Activitymanagerservice is responsible for power management functionsmactivitymanagerservice.initpowermanagement (); //Initialize DisplaymanagerserviceMdisplaymanagerservice = Msystemservicemanager.startservice (displaymanagerservice.class); //Initialize PackagemanagerserviceMpackagemanagerservice =Packagemanagerservice.main (Msystemcontext, Minstaller, Mfactorytestmode!=Factorytest.factory_test_off, Monlycore); ... ignore some code ...}}
This piece of code is important.
What is Activitymanagerservice? When was it initialized? What's the effect?
Activitymanagerservice, referred to as AMS, is the service-side object that is responsible for the life cycle of all activity in the system.
The timing of the initialization of the Activitymanagerservice is clear, that is, when the systemserver process is turned on, the Activitymanagerservice is initialized.
Following these steps, our Activitymanagerservice object has been created and the member variable initialization has been completed. And before that, when Createsystemcontext () was called to create the system context, the creation of Msystemcontext and Activitythread was also completed. Note that this is the process when the system process is turned on, after which the system's launcher program is opened and the system interface is loaded and displayed.
Android-activity START Process