Introduction to the Android Startup Process

Source: Internet
Author: User

Introduction to the Android Startup Process

In fact, everyone is not a god. It is impossible to know one thing at birth. It is the result of learning the day after tomorrow.

The Android startup process is too complicated. cainiao like ours cannot understand what he said for a long time.

So, I decided to talk about it myself. A simple talk would be a simple one.


Android startup can have two different understandings, which must be separated and cannot be as vague as others on the Internet.

Android startup can be understood as the startup of the Android system, and the second is the startup of the Android application.

The following opinions are purely personal opinions. If you have any questions, please correct them.

First look at the Android system boot: 1. I will not talk about the process of starting the Linux system to start the Linux system. The system is started from the BIOS. Running system/core/init. c is a necessary operation for Linux to start.
2. Where is the code used to start the Zygote process: system/core/init. c?
Init. c calls device/renesas/emev/init. rcinit. rc and calls framework/base/cmds/app_process/app_main.cpp.
App_main.cpp is responsible for starting the Zygote process.

What Zygote process? The Zygote process is actually a Linux service, so it can also be called the Zygote service. The Zygote service is actually in the same level as the system service, but the Zygote service will start first than the system service.
Why Zygote? The Zygote service specifically handles Android app startup, or specifically clones the Dalvik process. If a user starts an app with an app icon, the original Dalvik is the first to handle this event. The original Dalvik process will request the Zygote service to clone a new Dalvik, this new Dalvik will start the app (execute the main of ActivityThread ).
Why clone the Dalvik process? In fact, we can think in turn: What kind of process does the Android app need? Of course it's a Dalvik virtual machine process! Therefore, the Zygote service needs to clone a Dalvik process.
The question is, why don't we create a clone directly? Because cloning is faster than creating a new Dalvik, this is one of the special optimizations that Google calls for Dalvik.

What Should Zygote do after cloning? Zygote is an endless loop. It will always wait for others to initiate a request to clone Dalvik. Therefore, After cloning a Dalvik, it will wait for the next clone request.
How does the original Dalvik request Zygote to clone Dalvik? ZygoteInit. java in Dalvik will request the Zygote service to clone a Dalvik. The specific point is to clone all attributes and services of the Dalvik process for Android applications.
Why is there a Dalvik virtual machine process that can be cloned forever? How does this virtual machine process come from? The original Dalvik VM process was started when the Zygote process was started. The code is still in app_main.cpp, app_main.cpp will call AndroitRuntime. app, and AndroidRuntime. cpp will start the first Dalvik.
3. Start the system service Linux. After the Zygote service is started, immediately start the system service.
I don't know much about system services. I don't know much about system services. We only know that Zygote and Zygote are good friends, Zygote is the boss, and system service is the younger brother. These two good friends have supported the half-day Android runtime environment. It is estimated that the system service provider, like its name, is only a required service for some Android applications.
Next, start the Android app: 1. The process for creating an app is completed by the original Dalvik. In fact, the original Dalvik clones a Dalvik from itself in a request to the Zygote service. 2. Create the main thread. This step is completed by the Dalvik cloned from the original Dalvik. The created main thread class is ActivityThread. java. The four major components are started by the ActivityManager, but they do not directly manage the Activity. The ActivityManager is responsible for starting the ActivityManager, And the ActivityManager is responsible for managing the Activity lifecycle, all onCreate and other methods are called by ActivityManager. This step is the real entry point of the application. In the future, never mind that onCreate of the Activity is the entry point of the Android application! The main method of ActivityThread. 3. This step is also completed by the Dalvik cloned from the original Dalvik.
PS: Android project compilation and running process: 1. The javac tool first compiles the java file into a class file. 2. The dx tool then compiles the class file into the classes. dex file. 3. The dx tool then packs classes. dex and other resource files and signs them into an apk file. 4. The abd tool then installs the apk on the Android simulator AVD. 5. Run apk with AVD.

Related Article

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: info-contact@alibabacloud.com 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.