bind service client不引用aidl
作者:互联网
bind service client不引用aidl
创建单独的aidl仓库,在该仓库添加aidl文件,IService.aidl,定义可供client连接的aidl类
添加aidl文件 IClientListener.aidl,定义可供client接收消息的aidl类
1.在aidl仓库创建 MyManager,在 connectService方法,启动并绑定服务
public void connectService(ClientListener clientListener){
}
2.service 端定义接口实现,并在onBind 回调中返回
private IService.Stub mService = new IService.Stub(){
public void register2Service(IClientListener iClientListener) {
//蒋监听注册到service
}
...
}
public IBinder onBind(Intent intent) {
LogUtil.d(TAG, "onBind");
return mService;
}
3.在aidl仓库 实现client aidl实现
private IClientListener.Stub mClientListener = new IClientListener.Stub(){
...
}
在aidl 声明和IClientListener 一样方法的接口ClientListener让client实现接口,在调用处理ClientListener 回调,
标签:IService,service,aidl,bind,Stub,client,IClientListener 来源: https://www.cnblogs.com/adamli/p/15468909.html