美文网首页
Zygote冷启动 启动时间收集(二)

Zygote冷启动 启动时间收集(二)

作者: 馒Care | 来源:发表于2025-04-25 17:00 被阅读0次

前面我们讲解了Zygote冷启动Application应该设置启动时间的位置是attachBaseContext
Zygote冷启动 启动时间收集

首先看ActivityThtread唤起Activity的方法

 public void handleMessage(Message msg) {
      ···
      case RELAUNCH_ACTIVITY:
          handleRelaunchActivityLocally((IBinder) msg.obj);
      break;
    ···
}

handleRelaunchActivityLocally最终会走到performLaunchActivity

// Activity resources must be initialized with the same loaders as the
                // application context.
                appContext.getResources().addLoaders(
                        app.getResources().getLoaders().toArray(new ResourcesLoader[0]));

                appContext.setOuterContext(activity);
                activity.attach(appContext, this, getInstrumentation(), r.token,
                        r.ident, app, r.intent, r.activityInfo, title, r.parent,
                        r.embeddedID, r.lastNonConfigurationInstances, config,
                        r.referrer, r.voiceInteractor, window, r.configCallback,
                        r.assistToken);

                if (customIntent != null) {
                    activity.mIntent = customIntent;
                }

performLaunchActivity() 中调 OnCreate() 方法前会调用 Activity 的 attach() 方法,这里详细的可以看这里
Window WindowManager WindowManagerService

可以看到Activity里面的attatch方法

final void attach(Context context, ActivityThread aThread,
            Instrumentation instr, IBinder token, int ident,
            Application application, Intent intent, ActivityInfo info,
            CharSequence title, Activity parent, String id,
            NonConfigurationInstances lastNonConfigurationInstances,
            Configuration config, String referrer, IVoiceInteractor voiceInteractor,
            Window window, ActivityConfigCallback activityConfigCallback) {
        //省略部分代码
        ...
 
        mWindow = new PhoneWindow(this, window, activityConfigCallback);
        mWindow.setWindowControllerCallback(this);
        mWindow.setCallback(this);
        mWindow.setOnWindowDismissedCallback(this);
        mWindow.getLayoutInflater().setPrivateFactory(this);
        //省略部分代码
        ...
       
        mWindow.setWindowManager(
                (WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
                mToken, mComponent.flattenToString(),
                (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
        if (mParent != null) {
            mWindow.setContainer(mParent.getWindow());
        }
 
        mWindowManager = mWindow.getWindowManager();
        //省略部分代码
        ...
        
    }

attatch方法中创建了Window唯一实现类PhoneWindow类型的mWindow对象,mWindowManager对象也是从PhoneWindow获取的。那么他是在哪里初始化的呢?

相关文章

  • Zygote冷启动 启动时间收集(一)

    冷启动 启动时间收集 上一篇说道Zygote启动流程,本篇描述冷启动时间收集 首先我们知道冷启动会先初始化Appl...

  • 启动优化1

    目录 一、冷启动定义 二、 冷启动和热启动 三、冷启动、热启动的区别 四、冷启动时间的计算 五、冷启动流程 六、冷...

  • Zygote冷启动流程

    http://liuwangshu.cn/framework/applicationprocess/1.html[...

  • 冷启动和热启动

    一,什么是冷启动和热启动 二,冷启动流程 三,怎么对冷启动进行优化 一,什么是冷启动和热启动 定义:冷启动就是启动...

  • 冷启动优化

    一、什么是冷启动? 冷启动的定义/冷启动和热启动的区别/冷启动时间的计算 冷启动的定义:就是在启动应用前,系统中没...

  • android应用冷启动

    1 什么是冷启动 冷启动/热启动,冷启动消耗时间最长,冷启动就是在启动应用前,系统中没有该应用的任何进程信...

  • 面试题:APP启动优化

    一、APP启动分为冷启动和热启动 二、APP冷启动三大阶段 三、APP启动优化 四、共享缓存机制

  • ios性能优化

    1.项目启动 冷启动和热启动 APP 启动分为冷启动(Cold Launches),当 APP 长时间没有被启动的...

  • 启动优化的原理以及操作

    首先我们要知道,启动是分为冷启动和热启动的。启动优化主要就是优化冷启动的时间。冷启动又可以分为两个部分:pre_m...

  • 冷启动和热启动 iOS 启动速度优化

    冷启动和热启动APP 启动分为冷启动(Cold Launches),当 APP 长时间没有被启动的时候,用户再次启...

网友评论

      本文标题:Zygote冷启动 启动时间收集(二)

      本文链接:https://www.haomeiwen.com/subject/ytkllrtx.html