Because the "-- runtime-init" parameter is specified in the previous Step 3, it indicates that the runtime Library is to be initialized for the newly created process. Therefore, the preceding parseArgs. the runtimeInit value is true, so you can continue to execute RuntimeInit. zygoteInit is further processed. Next:
Step 8. RuntimeInit. zygoteInit
This function is defined in the frameworks/base/core/java/com/android/internal/OS/RuntimeInit. java file:
- [java] view plaincopypublic class RuntimeInit {
- ......
- public static final void zygoteInit(String[] argv)
- throws ZygoteInit.MethodAndArgsCaller {
- // TODO: Doing this here works, but it seems kind of arbitrary. Find
- // a better place. The goal is to set it up for applications, but not
- // tools like am.
- System.setOut(new AndroidPrintStream(Log.INFO, "System.out"));
- System.setErr(new AndroidPrintStream(Log.WARN, "System.err"));
- commonInit();
- zygoteInitNative();
- int curArg = 0;
- for ( /* curArg */ ; curArg < argv.length; curArg++) {
- String arg = argv[curArg];
- if (arg.equals("--")) {
- curArg++;
- break;
- } else if (!arg.startsWith("--")) {
- break;
- } else if (arg.startsWith("--nice-name=")) {
- String niceName = arg.substring(arg.indexOf('=') + 1);
- Process.setArgV0(niceName);
- }
- }
- if (curArg == argv.length) {
- Slog.e(TAG, "Missing classname argument to RuntimeInit!");
- // let the process exit
- return;
- }
- // Remaining arguments are passed to the start class's static main
- String startClass = argv[curArg++];
- String[] startArgs = new String[argv.length - curArg];
- System.arraycopy(argv, curArg, startArgs, 0, startArgs.length);
- invokeStaticMain(startClass, startArgs);
- }
- ......
- }
There are two key function calls: zygoteInitNative function call and invokeStaticMain function call. The former is the initialization of the Binder driver, so that the Binder object in the process can smoothly communicate with the Binder process. The next function call is the entry function of the execution process. Here, the main function of the startClass class is executed, this startClass is the "android. app. activityThread "value, indicating to execute android. app. main function of the ActivityThread class.
Let's take a look at the call process of the zygoteInitNative function, and then return to the RuntimeInit. zygoteInit function to see how it calls the main function of the android. app. ActivityThread class.