Source code analysis of Android Application Process Startup Process (8)

Source: Internet
Author: User

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:

 
 
  1. [java] view plaincopypublic class RuntimeInit { 
  2. ...... 
  3. public static final void zygoteInit(String[] argv) 
  4. throws ZygoteInit.MethodAndArgsCaller { 
  5. // TODO: Doing this here works, but it seems kind of arbitrary. Find 
  6. // a better place. The goal is to set it up for applications, but not 
  7. // tools like am. 
  8. System.setOut(new AndroidPrintStream(Log.INFO, "System.out")); 
  9. System.setErr(new AndroidPrintStream(Log.WARN, "System.err")); 
  10. commonInit(); 
  11. zygoteInitNative(); 
  12. int curArg = 0; 
  13. for ( /* curArg */ ; curArg < argv.length; curArg++) { 
  14. String arg = argv[curArg]; 
  15. if (arg.equals("--")) { 
  16. curArg++; 
  17. break; 
  18. } else if (!arg.startsWith("--")) { 
  19. break; 
  20. } else if (arg.startsWith("--nice-name=")) { 
  21. String niceName = arg.substring(arg.indexOf('=') + 1); 
  22. Process.setArgV0(niceName); 
  23. if (curArg == argv.length) { 
  24. Slog.e(TAG, "Missing classname argument to RuntimeInit!"); 
  25. // let the process exit 
  26. return; 
  27. // Remaining arguments are passed to the start class's static main 
  28. String startClass = argv[curArg++]; 
  29. String[] startArgs = new String[argv.length - curArg]; 
  30. System.arraycopy(argv, curArg, startArgs, 0, startArgs.length); 
  31. invokeStaticMain(startClass, startArgs); 
  32. ...... 

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.

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.