原始碼探探之startActivity 二

2021-09-11 10:04:51 字數 4504 閱讀 8832

原始碼基於api26

@override

public final void schedulelaunchactivity(intent intent, ibinder token, int ident,

activityinfo info, configuration curconfig, configuration overrideconfig,

compatibilityinfo compatinfo, string referrer, ivoiceinteractor voiceinteractor,

int procstate, bundle state, persistablebundle persistentstate,

listpendingresults, listpendingnewintents,

boolean notresumed, boolean isforward, profilerinfo profilerinfo) 複製**

接著看handler

public void handlemessage(message msg)  break;複製**
接著handlelaunchactivity()

private void handlelaunchactivity(activityclientrecord r, intent customintent, string reason) 

// 確保執行最新的配置

handleconfigurationchanged(null, null);

if (locallo**) slog.v(

tag, "handling launch of " + r);

// 建立activity之前初始化windowmanagerglobal,獲取iwindowmanger

windowmanagerglobal.initialize();

//啟動activity

activity a = performlaunchactivity(r, customintent);

//activity不為null

if (a != null)

}} else catch (remoteexception ex)

}}複製**

接著performlaunchactivity()

private activity performlaunchactivity(activityclientrecord r, intent customintent) 

//component檢驗

componentname component = r.intent.getcomponent();

if (component == null)

//原activity不為空可新建component

if (r.activityinfo.targetactivity != null)

//建立contextimpl

activity activity = null;

try

} catch (exception e)

}try

if (debug_configuration) slog.v(tag, "launching activity "

+ r.activityinfo.name + " with config " + config);

window window = null;

if (r.mpendingremovewindow != null && r.mpreservewindow)

//context表示為activity

//準備好了嗎我們的activity來了

r.embeddedid, r.lastnonconfigurationinstances, config,

r.referrer, r.voiceinteractor, window, r.configcallback);

if (customintent != null)

r.lastnonconfigurationinstances = null;

checkandblockfornetworkaccess();

activity.mstartedactivity = false;

int theme = r.activityinfo.getthemeresource();

//設定主題

if (theme != 0)

activity.mcalled = false;

//activity已啟動執行oncreate()了

if (r.ispersistable()) else

if (!activity.mcalled)

r.activity = activity;

r.stopped = true;

//沒有關閉就要執行onstart()了

if (!r.activity.mfinished)

if (!r.activity.mfinished)

} else

if (r.state != null)

}//沒有finish()執行onpostcreate()

if (!r.activity.mfinished) else

if (!activity.mcalled) }}

r.paused = true;

mactivities.put(r.token, r);

} catch (supernotcalledexception e) catch (exception e)

}return activity;

}複製**

系不繫上面這個方法有點長了,但是很顯然是我們開發平時接觸很近的方法了

再看看attach()

//主要是給我們activity賦一大堆值

final void attach(context context, activitythread athread,

instrumentation instr, ibinder token, int ident,

charsequence title, activity parent, string id,

nonconfigurationinstances lastnonconfigurationinstances,

configuration config, string referrer, ivoiceinteractor voiceinteractor,

window window, activityconfigcallback activityconfigcallback)

if (info.uioptions != 0)

//看見沒這就是uithread

muithread = thread.currentthread();

//主線程為activitythread

mmainthread = athread;

//原來這貨再這賦值的每乙個activity都有這個監控類

minstrumentation = instr;

mtoken = token;

mident = ident;

mintent = intent;

mreferrer = referrer;

mcomponent = intent.getcomponent();

mactivityinfo = info;

mtitle = title;

mparent = parent;

membeddedid = id;

mlastnonconfigurationinstances = lastnonconfigurationinstances;

if (voiceinteractor != null) else

}mwindow.setwindowmanager(

(windowmanager)context.getsystemservice(context.window_service),

mtoken, mcomponent.flattentostring(),

(info.flags & activityinfo.flag_hardware_accelerated) != 0);

if (mparent != null)

mwindowmanager = mwindow.getwindowmanager();

mcurrentconfig = config;

mwindow.setcolormode(info.colormode);

}複製**

還要問我activity啟動了沒有嗎,我說沒有

schedulelaunchactivity()、handlelaunchactivity()、performlaunchactivity()

將activity的相關資訊淋漓盡致的展現,沒事多看看,我還沒專研細緻的方法呢。

原始碼解析 JDK原始碼之LinkedHashMap

linkedhashmap原始碼,基於 jdk1.6.43 他繼承了hashmap,並且實現了插入和訪問的有序功能 public class linkedhashmapextends hashmapimplements map 其也有乙個entry內部類,繼承了 hashmap 的entry 內部類...

原始碼閱讀 Glide原始碼閱讀之with方法(一)

前言 本篇基於4.8.0版本 原始碼閱讀 glide原始碼閱讀之with方法 一 原始碼閱讀 glide原始碼閱讀之load方法 二 原始碼閱讀 glide原始碼閱讀之into方法 三 大多數情況下,我們使用glide 就一句 但是這一句 裡面蘊含著成噸的 with方法有以下幾個過載方法 publi...

Spring原始碼解析之 Aop原始碼解析(2)

spring aop 更多的是oop開發模式的乙個補充,幫助oop以更好的方式來解決對於需要解決業務功能模組之上統一管理 的功能 以一副圖來做為aop功能的說明更直觀些。對於類似系統的安全檢查,系統日誌,事務管理等相關功能,物件導向的開發方法並沒有更好的解決方法 aop引入了一些概念。更多的是spr...