如何在Android IPC中返回活动对象列表
尝试使用AIDL方法将某些接口从Android服务应用程序远程连接到另一个客户端应用程序。如何在Android IPC中返回活动对象列表,android,ipc,generic-list,aidl,Android,Ipc,Generic List,Aidl,尝试使用AIDL方法将某些接口从Android服务应用程序远程连接到另一个客户端应用程序。 因此我在IJobController.aidl中有一个接口IJobController: 导入com.example.jobs.api.IJobExecutionContext interface IJobController { List<IJobExecutionContext> getCurrentlyExecutingJobs(); ... } 当在gen文件夹中编译
因此我在IJobController.aidl中有一个接口IJobController:
导入com.example.jobs.api.IJobExecutionContext
interface IJobController {
List<IJobExecutionContext> getCurrentlyExecutingJobs();
...
}
当在gen文件夹中编译这些定义时,在生成的IJobController.java文件中会出现如下错误:
Type mismatch: cannot convert from ArrayList<IBinder> to List<IJobExecutionContext>
The method writeBinderList(List<IBinder>) in the type Parcel is not applicable for the arguments (List<IJobExecutionContext>)
类型不匹配:无法从ArrayList转换为List
类型包中的方法writeBinderList(List)不适用于参数(List)
据我所知,这些接口可以与基本类型、Parcelable等一起用于列表(或地图)。
在另一种方法中,我只返回一个AIDL接口,一切正常,但在列表容器中似乎不正常
我是否需要返回一个原始列表,或者一个IJobExecutionContext实现的列表,该实现也是可打包的
谢谢。问题是,Binder对您的界面不了解,它不知道如何处理它。Binder知道如何仅封送和解封送基元类型。在其他情况下,您需要解释如何执行这些实现Parcelable接口的操作。因此,据我所知,您不能使用AIDL文件中的接口。您需要用实现此接口的类替换
IJobExecutionContext
。此外,此类还必须实现Parcelable
接口
Type mismatch: cannot convert from ArrayList<IBinder> to List<IJobExecutionContext>
The method writeBinderList(List<IBinder>) in the type Parcel is not applicable for the arguments (List<IJobExecutionContext>)