Zygote冷啟動(dòng) 啟動(dòng)時(shí)間收集(二)

前面我們講解了Zygote冷啟動(dòng)Application應(yīng)該設(shè)置啟動(dòng)時(shí)間的位置是attachBaseContext
Zygote冷啟動(dòng) 啟動(dòng)時(shí)間收集

首先看ActivityThtread喚起Activity的方法

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

handleRelaunchActivityLocally最終會(huì)走到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() 中調(diào) OnCreate() 方法前會(huì)調(diào)用 Activity 的 attach() 方法,這里詳細(xì)的可以看這里
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方法中創(chuàng)建了Window唯一實(shí)現(xiàn)類PhoneWindow類型的mWindow對(duì)象,mWindowManager對(duì)象也是從PhoneWindow獲取的。那么他是在哪里初始化的呢?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容