本篇內(nèi)容介紹了“Android中Binder機(jī)制的介紹和使用”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
松溪ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書(shū)合作)期待與您的合作!
binder用于android進(jìn)程間的通訊。客戶(hù)端程序和系統(tǒng)服務(wù),客戶(hù)端進(jìn)程之間,都是通過(guò)binder進(jìn)行進(jìn)程間通訊的。
客戶(hù)端和系統(tǒng)服務(wù)通訊的入口:cotext.getSystemService(String name)
android.app.ContextImpl:
@Override
public Object getSystemService(String name) {
return SystemServiceRegistry.getSystemService(this, name);
}
android.app.SystemServiceRegistry:
靜態(tài)代碼塊注冊(cè)系統(tǒng)服務(wù):
static {
registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class,
new CachedServiceFetcher<AccessibilityManager>() {
@Override
public AccessibilityManager createService(ContextImpl ctx) {
return AccessibilityManager.getInstance(ctx);
}});
registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class,
new CachedServiceFetcher<CaptioningManager>() {
@Override
public CaptioningManager createService(ContextImpl ctx) {
return new CaptioningManager(ctx);
}});
registerService(Context.ACCOUNT_SERVICE, AccountManager.class,
new CachedServiceFetcher<AccountManager>() {
@Override
public AccountManager createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService(Context.ACCOUNT_SERVICE);
IAccountManager service = IAccountManager.Stub.asInterface(b);
return new AccountManager(ctx, service);
}});
....
ServiceManager、ServiceManagerNative:
serviceManager是管理系統(tǒng)服務(wù)的一個(gè)工具類(lèi)。
sServiceManager = ServiceManagerNative
.asInterface(Binder.allowBlocking(BinderInternal.getContextObject()));
getService方法:利用ServiceManagerProxy類(lèi)通過(guò)進(jìn)程間通訊的方式,獲取其他服務(wù)在binder驅(qū)動(dòng)中的binder對(duì)象mRemote。
xxx.Stub.asInterface(binder):
利用getService獲取到的binder對(duì)象實(shí)例化相應(yīng)服務(wù)的Proxy對(duì)象,返回給客戶(hù)端,供客戶(hù)端使用。
返回系統(tǒng)服務(wù):
/**
* Gets a system service from a given context.
*/
public static Object getSystemService(ContextImpl ctx, String name) {
ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name);
return fetcher != null ? fetcher.getService(ctx) : null;
}
B應(yīng)用進(jìn)程調(diào)用A應(yīng)用進(jìn)程
B bindservice 向AmS請(qǐng)求啟動(dòng)B應(yīng)用的service。啟動(dòng)service成功后會(huì)像AmS返回一個(gè)(binder驅(qū)動(dòng)中的mRemote)binder,AmS會(huì)以該binder為參數(shù)調(diào)用ActivityThread類(lèi)中的ApplicatonThread對(duì)象。接著會(huì)在ApplicationThread中回調(diào)conn接口。最后,B進(jìn)程可以利用該binder調(diào)用A應(yīng)用提供的功能。
“Android中Binder機(jī)制的介紹和使用”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
網(wǎng)站欄目:Android中Binder機(jī)制的介紹和使用
地址分享:http://muchs.cn/article10/pdhedo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、App設(shè)計(jì)、定制開(kāi)發(fā)、網(wǎng)站制作、網(wǎng)站策劃、網(wǎng)站營(yíng)銷(xiāo)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)