// Declare any non-default types here with import statements import com.idisfkj.aidldemo.HelloMessage; interface IRemoteService { /** * Demonstrates some basic types that you can use as parameters * and return values in AIDL. */ void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString);
public static final Creator<HelloMessage> CREATOR = new Creator<HelloMessage>() { @Override public HelloMessage createFromParcel(Parcel in) { return new HelloMessage(in); }
@Override public HelloMessage[] newArray(int size) { return new HelloMessage[size]; } };
public String getMessage() { return message; }
public void setMessage(String message) { this.message = message; }
public int getpId() { return pId; }
public void setpId(int pId) { this.pId = pId; }
@Override public int describeContents() { return 0; }
@Override public void writeToParcel(Parcel parcel, int i) { parcel.writeString(message); parcel.writeInt(pId); } }
// Declare any non-default types here with import statements
parcelable HelloMessage;
最后在前面新建的IRemoteService.aidl文件中导入该类型的包。(可以查看前面贴的代码,我已经实现了),这样所需的.aidl文件与接口都已经建好了,最后再Build -> Make Project(如果你是在Module中则Build -> Make Module App)。完了之后我们就能在build/generated/source/aidl中查看生成的IRemoteService。打开之后能看到如下信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
public interface IRemoteService extends android.os.IInterface { /** Local-side IPC implementation stub class. */ public static abstract class Stub extends android.os.Binder implements com.idisfkj.aidldemo.IRemoteService { private static final java.lang.String DESCRIPTOR = "com.idisfkj.aidldemo.IRemoteService"; /** Construct the stub at attach it to the interface. */ public Stub() { this.attachInterface(this, DESCRIPTOR); } /** * Cast an IBinder object into an com.idisfkj.aidldemo.IRemoteService interface, * generating a proxy if needed. */ public static com.idisfkj.aidldemo.IRemoteService asInterface(android.os.IBinder obj) { //省略