回调的对象 Test.java (Implements Parcelable):
package com.app.pack.classes;
public class Test implements Parcelable {
private int test = 33;
protected Test(Parcel in) {
test = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(test);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Test> CREATOR = new Creator<Test>() {
@Override
public Test createFromParcel(Parcel in) {
return new Test(in);
}
@Override
public Test[] newArray(int size) {
return new Test[size];
}
};
}
与回调对象同名的AIDL文件 Test.aidl (Declares the class I want to send):
package com.app.pack.aidl;
parcelable Test;
调用接口的AIDL文件 TestService.aidl (provides the method that returns a Test object):
package com.app.pack.aidl;
import com.app.pack.aidl.Test;
interface TestService{
Test getAll(in int[] listOfInts);
}
这样写编译会报错:
refusing to generate code from aidl file defining parcelable couldn’t find import for class xxxxx
原因:
回调的对象类 (Test.java)的包名 与 回调对象同名的AIDL文件(Test.aidl)的包名不一致会导致此问题,这两个文件(Test.java 和 Test.aidl)的包名必须一致
Test类的包名:com.app.pack.classes
Test.aidl 文件的包名:com.app.pack.aidl