AIDL 最广泛与最简单的应用是与四大组件之一 Serivce 的配合使用了。我们都知道,启动一个 Serivce 有两种方式:1、通过 startService 的方式;2、通过 bindService 的方式。 通过 binService 方式启动的 Service 所返回的对象类型,就可以理解为是 AIDL 跨进程通信类型。
一.服务端
首先创建一个服务端的apk项目,创建AIDL文件.
创建完成后结构如下:
可以看到AIDL文件所在的包和java包路径是一致的.
根据业务需求修改所创建的aidl文件.
package com.example.myserver;
// Declare any non-default types here with import statements
interface myhonaidl {
String getInfo(String info);
}
接着创建对应的service.
package com.example.myserver;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import andr