用的时候要在mian目录下创建aidl文件,而且如果 用到了自定义类,必须在对应的创建个aidl文件,指定它是parcelable

aidl填坑_android

Mydata.aidl定义

aidl填坑_android_02

 

 

MyData的代码 需要实现parcelable接口

package com.demo.aidl.model;

import android.os.Parcel;
import android.os.Parcelable;


/**
* Created by xwg on 2019/12/18.
* describe TODO
*/
public class MyData implements Parcelable {
public int getData1() {
return data1;
}

public void setData1(int data1) {
this.data1 = data1;
}

public int getData2() {
return data2;
}

public void setData2(int data2) {
this.data2 = data2;
}

private int data1;
private int data2;

public MyData() {
}

protected MyData(Parcel in) {
readFromParcel(in);
}

public static final Creator<MyData> CREATOR = new Creator<MyData>() {
@Override
public MyData createFromParcel(Parcel in) {
return new MyData(in);
}

@Override
public MyData[] newArray(int size) {
return new MyData[size];
}
};

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(data1);
dest.writeInt(data2);
}

/**
* 从Parcel中读取数据
**/
public void readFromParcel(Parcel in) {
data1 = in.readInt();
data2 = in.readInt();
}

// @NonNull
// @Override
// public String toString() {
// return "data1:" + data1 + ",data2:" + data2;
// }
}