本篇內容介紹了“Android中Binder機制的介紹和使用”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
松溪ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為成都創新互聯公司的ssl證書銷售渠道,可以享受市場價格4-6折優惠!如果有意向歡迎電話聯系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
binder用于android進程間的通訊。客戶端程序和系統服務,客戶端進程之間,都是通過binder進行進程間通訊的。
客戶端和系統服務通訊的入口:cotext.getSystemService(String name)
android.app.ContextImpl:
@Override
public Object getSystemService(String name) {
return SystemServiceRegistry.getSystemService(this, name);
}
android.app.SystemServiceRegistry:
靜態代碼塊注冊系統服務:
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是管理系統服務的一個工具類。
sServiceManager = ServiceManagerNative
.asInterface(Binder.allowBlocking(BinderInternal.getContextObject()));
getService方法:利用ServiceManagerProxy類通過進程間通訊的方式,獲取其他服務在binder驅動中的binder對象mRemote。
xxx.Stub.asInterface(binder):
利用getService獲取到的binder對象實例化相應服務的Proxy對象,返回給客戶端,供客戶端使用。
返回系統服務:
/**
* 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應用進程調用A應用進程
B bindservice 向AmS請求啟動B應用的service。啟動service成功后會像AmS返回一個(binder驅動中的mRemote)binder,AmS會以該binder為參數調用ActivityThread類中的ApplicatonThread對象。接著會在ApplicationThread中回調conn接口。最后,B進程可以利用該binder調用A應用提供的功能。
“Android中Binder機制的介紹和使用”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯網站,小編將為大家輸出更多高質量的實用文章!
網站欄目:Android中Binder機制的介紹和使用
地址分享:http://vcdvsql.cn/article10/pdhedo.html
成都網站建設公司_創新互聯,為您提供定制網站、App設計、定制開發、網站制作、網站策劃、網站營銷
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯