Deep understanding of Android Learning Note (iii) ——— zygote

Source: Internet
Author: User

1. Zygote itself is a native application, independent of the driver, kernel, created by the Init process according to the INIT.RC configuration items.

2. Zygote is the step to create the Java world with Pangu, creating the Java World:

(1) Create the Appruntime object and call it start. Subsequent activities are controlled by Appruntime.

(2) Call STARTVM to create the Java virtual machine, and then call Startreg to register the JNI function.

(3) The main function of the class is called through JNI to enter the Java world.

(4) Call Registerzygotesocket to establish a socket as the IPC Communication Service, through which zygote can respond to future generations ' requests. At the same time, zygote pre-load classes and resources by calling Preloadclasses and Preloadresouces.

(5) Create a process system_server through Startsystemserver to serve the Java world. The process is at the core of the framework and the services of the system in the Java world reside in that process.

(6) Zygote calls the Runselectloopmode function into the loop, and this function uses the socket in (4). This function is primarily used to handle customer connections and customer requests. The client is represented by the Zygoteconnection object in Zygote, and the client's request is handled by Zygoteconnection's RunOnce.

3. Systemserver (system_server) Birth process:

(1) Zygoteinit call Startsystemserver to create the system_server process.

(2) System_server call Handlesystemprocess to complete his mission.

(3) Handlesystemprocess throws an exception and eventually calls's main function.

(4) The main function loads the and calls the native Init1 function.

(5) The INIT1 function invokes's init2 function through JNI, and the Init2 function creates a thread for loading various services.

(6) The INIT1 function eventually joins the main thread of the process into the binder communication system.

4. Zygote Split Breeding Example

Activitymanagerservice is created by Systemserver and resides in the Systemserver process. Use StartActivity to start a new activity, which is attached to a process that has not yet started, which starts the process:

(1) Activitymanagerservice sends a request message to zygote.

(2) Whenever a request data is sent, Zygote's Runselectloopmode function calls Zygoteconnection's RunOnce function fork to create the child process.

(3) The child process calls the main function of is actually the process corresponding to the APK program in Android, and its main function is the main function of the APK program. Since then, the new activity has run.

Deep understanding of Android Learning Note (iii) ——— zygote

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: 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.