Android zygote与进程创建(二)

启动应用进程:

       我们在上一篇介绍ActivityThread和ActivityManagerService时已经讲过,程序的主入口是在ActivityThread的main函数,activity的startActivity最终是在ActivityManagerService中执行的,那么应用程序的进程是怎么创建的?看下类图:

3.jpg

       我们再来看看ActivityManagerService中的startProcessLocked方法。

java代码:
  1. int pid = Process.start("android.app.ActivityThread", 
  2. mSimpleProcessManagement ? app.processName : null, uid, uid, gids, debugFlags, null); 
复制代码

        通过Process的start方法来创建进程。

java代码:
  1. / ** 
  2. *通过Zygote进程来创建新的vm进程 
  3. */ 
  4. public static final int start(final String processClass,final String niceName,int uid, int gid, int[] gids,int debugFlags,String[] zygoteArgs) 

  5. if (supportsProcesses()) { 
  6. try { 
  7. return startViaZygote(processClass, niceName, uid, gid, gids, 
  8. debugFlags, zygoteArgs); //argsForZygote.add("--runtime-init")初始化运行环境 
  9. } catch (ZygoteStartFailedEx ex) { 
  10. Log.e(LOG_TAG, "Starting VM process through Zygote failed"); 
  11. throw new RuntimeException( 
  12. "Starting VM process through Zygote failed", ex); 

  13. } else { 
  14. // Running in single-process mode 
  15. Runnable runnable = new Runnable() { 
  16. public void run() { 
  17. Process.invokeStaticMain(processClass); 

  18. }; 
  19. // Thread constructors must not be called with null names (see spec). 
  20. if (niceName != null) { 
  21. new Thread(runnable, niceName).start(); 
  22. } else { 
  23. new Thread(runnable).start(); 

  24. return 0; 


复制代码

系列之Android zygote与进程创建(一)的帖子链接 http://www.eoeandroid.com/thread-82883-1-1.html
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值