先回顾一下aidl的使用方法,可以参考上篇介绍的AIDL怎么用,链接如下:
Server端:
- 创建aidl接口文件以及数据(Parcelable)文件;
- 创建service文件,在AndroidManifest中声明action;
3、在service文件中添加IxxxInterface.Stub, 以及对应aidl接口实现,例如:
private IMediaShareInterface.Stub mIMediaShareMgr = new IMediaShareInterface.Stub() {
@Override
public void onMediaSharing(MediaData data) throws RemoteException {
}
};
Client端:
- 创建和server端相应的aidl文件(可以直接从server端复制一份);
- 在Activity中添加ServiceConnection,在onStart中添加bindService,在onStop中添加unbindService,例如:
private ServiceConnection mServiceCon