Binder 机制
概述
Binder 是 Android 系统的核心 IPC 机制,基于 C/S 架构。
架构
Client → Proxy → Binder Driver → Stub → Server关键组件
- Binder Driver — 内核模块,负责进程间数据传递
- ServiceManager — 服务注册与查找
- AIDL — 接口定义语言,自动生成 Proxy/Stub
AIDL 示例
java
// IRemoteService.aidl
interface IRemoteService {
int getPid();
String getName();
}使用场景
- Activity 与 Service 通信
- ContentProvider 数据共享
- 系统服务调用(WindowManager、ActivityManager 等)