使用AIDL双向通信
来源:互联网 发布:不调用淘宝客api 编辑:程序博客网 时间:2024/06/06 00:47
IInterface.Stub(),客户进程(调用远程Service的应用)也要实现一个ICallBack.Stub(),而该ICallBack也是通过AIDL定义。例子如下:
IService .aidl
interface IService { void init(ICallback callBack); }
ICallback.aidl
interface ICallback { void onResult(String result);void onError(String errorMsg, int errorCode);}
远程Service中的一个内部类:
private final IService.Stub mBinder = new IService.Stub() {public ICallback mCallBack;@Overridepublic void init(ICallback callBack)throws RemoteException {mCallBack = callBack;}}
在Android group中也有一个类似的话题:
https://groups.google.com/forum/#!topic/android-developers/X3SCuioxpYE
其中一个回答建议参考android api example的Remote Service.
https://android.googlesource.
final RemoteCallbackList<IRemoteServiceCallback> mCallbacks = new RemoteCallbackList<IRemoteServiceCallback>();一下是RemoteCallbackList的文档:
To use this class, simply create a single instance along with your service, and call itsregister(E)
andunregister(E)
methods as client register and unregister with your service. To call back on to the registered clients, use beginBroadcast()
,getBroadcastItem(int)
, andfinishBroadcast()
.
If a registered callback's process goes away, this class will take care of automatically removing it from the list. If you want to do additional work in this situation, you can create a subclass that implements theonCallbackDied(E)
method.
可见用RemoteCallbackList来管理这些远程回调接口更为方便。
- 使用AIDL双向通信
- Android AIDL双向通信
- AIDL实现跨APP通信(双向通信)
- AIDL 客户端与服务端的双向通信
- AIDL 客户端与服务端的双向通信
- Android 跨进程双向通信(Messenger与AIDL)详解
- 使用AIDL
- AIDL使用
- AIDL使用
- AIDL使用
- 使用管道实现进程间的双向通信
- 使用 Messenger 来实现Service的双向通信
- Android使用Messenger实现进程间双向通信
- 使用AIDL写Service
- Android AIDL使用详解
- AIDL的使用
- AIDL使用示例
- Android AIDL使用详解
- Spring中Quartz调度器的使用
- 基于RFID技术的预制件管理系统的开发
- pcl点云库学习笔记
- Swift 绘图板功能完善以及终极优化
- 三消游戏--冒险王总结
- 使用AIDL双向通信
- 提高 linux 下 firefox 播放 flash 流畅度
- 如何用Spring发送邮件
- Nginx的安装与第三方模块编译
- 线程池
- 第十三章 while and for Loops
- Qcon2015全球软件开发者大会北京站PPT
- Mysql 锁原理很多和Oracle 相似
- iBatis使用SQLServer出现Can't start a cloned connection while in manual transaction mode.错误