Android中的Resources解析

2021-08-10 17:55:05 字數 2566 閱讀 8586

private

// 1.1 獲取應用資訊loadedapk

data

.info = getpackageinfonocheck(data

.compatinfo);

.info);

// ......

}

一、獲取應用資訊loadedapk
public

compatibilityinfo compatinfo)

classloader baseloader, boolean securityviolation, boolean includecode,

boolean registerpackage) else

loadedapk packageinfo = ref != null ? ref.get() : null;

if (packageinfo == null || (packageinfo.mresources != null

&& !packageinfo.mresources.getassets().isuptodate()))

if (includecode) else

}return packageinfo;

}} if (packageinfo == null) throw

new illegalargumentexception("packageinfo");

// 直接建立乙個contextimpl物件

return

new contextimpl(null, mainthread,

packageinfo, null, null, false, null, null);}

private contextimpl(contextimpl container, activitythread mainthread,

loadedapk packageinfo, ibinder activitytoken, userhandle user, boolean restricted,

display display, configuration overrideconfiguration)

muser = user;

mpackageinfo = packageinfo;

mresourcesmanager = resourcesmanager.getinstance();

mdisplay = display;

moverrideconfiguration = overrideconfiguration;

final

int displayid = getdisplayid();

compatibilityinfo compatinfo = null;

if (container != null)

if (compatinfo == null && displayid == display.default_display)

mdisplayadjustments.setcompatibilityinfo(compatinfo);

mdisplayadjustments.setactivitytoken(activitytoken);

//packageinfo為loadedapk物件,也就是這裡呼叫了loadedapk的getresources方法

resources resources = packageinfo.getresources(mainthread);

if (resources != null)

}mresources = resources;

if (container != null) else else }}

public resources getresources(activitythread mainthread) 

return mresources;

}

resources gettoplevelresources(string resdir, string splitresdirs, string overlaydirs,

string libdirs, int displayid, configuration overrideconfiguration,

loadedapk pkginfo)

activitythread()
// resourcesmanager是乙個單例類,也就是說只會有乙份,所以我們所有資源的獲取最終呼叫的都是這個物件

public

static resourcesmanager getinstance()

return sresourcesmanager;}}

精品內容獨家發布平台

呈現與部落格不一樣的技術乾貨

android開發中的

線性布局 linear layout 相對布局 relative layout 布局 table layout 網格檢視 grid view 標籤布局 tab layout 列表檢視 list view 絕對布局 absolutelayout 1.實現tab的效果必須使用tabhost控制項作為ta...

Android中的Message Pool實現

為了避免物件頻繁建立銷毀帶來的開銷,可以採用乙個pool來維護這些物件,物件使用後可重新放到pool中被重新使用。message是乙個被頻繁使用的物件,因此message提供了乙個message pool。下面是message pool的實現。obtain方法用來從pool中獲取乙個message物...

Android中的廣播

android中的廣播。有發射廣播,必須要有收音機才能接到,並且調對臺才能得到對應的臺。1.電台發射廣播 使用intent,intent intent new intent 需要廣播的臺的名字 context。sendbroadcast intent 也就是先 生成一下你需要廣播的臺,然後用send...