【发布时间】:2015-06-07 13:18:04
【问题描述】:
我正在尝试使用 AIDL 中的 IPC 传递“响应”类对象。我已将课程打包:
public class Response implements Parcelable{
private long id;
private String speechString;
private List<String> responseString = new ArrayList<String>();
//set
...
}
//get
...
public Response(Parcel in) {
id = in.readLong();
speechString = in.readString();
if (in.readByte() == 0x01) {
responseString = new ArrayList<String>();
in.readList(responseString, String.class.getClassLoader());
} else {
responseString = null;
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(speechString);
if (responseString == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(responseString);
}
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Response createFromParcel(Parcel in) {
return new Response(in);
}
public Response[] newArray(int size) {
return new Response[size];
}
};
}
定义的 Response.aidl:
package com.example;
parcelable Response;
IappMain.aidl用于IPC,定义如下:
package com.example;
// Declare any non-default types here with import statements
import com.example.Response;
interface IOizuuMain {
int app(String aString);
Response getResponseByString(String string);
}
但是在构建项目时,它在 IappMain.java 中给了我以下错误: “错误:不兼容的类型:对象无法转换为响应”在这一行:
_result = com.example.Response.CREATOR.createFromParcel(_reply);
【问题讨论】:
-
你真的需要 AIDL 吗?我的意思是,你真的需要远程服务吗?
-
是的,因为我需要为我的应用程序的插件开发提供支持。
-
它与远程服务有什么关系?
-
插件作为远程服务安装
-
aidl中的String参数不需要
in(不确定对你的问题有什么影响)
标签: java android service android-studio aidl