使用aidl的Android远程服务

时间:2011-05-26 00:02:07

标签: android service aidl

我正在尝试使用Android AIDL在Eclipse中创建远程服务。我在/ src中创建了我的AIDL文件IRemoteService.aidl,如下所示:

package com.vtrandal.bluesentry;
interface IRemoteService {
    String getData();
}

在构建之后,我在/ gen中获得了一个包含以下类和方法的巨大文件IRemoteService.java(它与我在文档中看到的任何内容都不相似):

public interface IRemoteService extends android.os.IInterface

public static abstract class Stub extends android.os.Binder implements com.vtrandal.bluesentry.IRemoteService

private static final java.lang.String DESCRIPTOR = "com.vtrandal.bluesentry.IRemoteService";

public Stub()

public static com.vtrandal.bluesentry.IRemoteService asInterface(android.os.IBinder obj)

public android.os.IBinder asBinder()

public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException

private static class Proxy implements com.vtrandal.bluesentry.IRemoteService

Proxy(android.os.IBinder remote)

public android.os.IBinder asBinder()

public java.lang.String getInterfaceDescriptor()

public java.lang.String getData() throws android.os.RemoteException

public java.lang.String getData() throws android.os.RemoteException;

那么为什么IRemoteService.java包含文档中未提及的垃圾?我怎么可能知道怎么做呢?我怎么可能知道如何处理它?<​​/ p>

1 个答案:

答案 0 :(得分:3)

这是服务存根代码。需要实际与客户沟通。您自己没有编写任何用于客户端和服务之间通信的代码,是吗?毕竟它不是那么简单,它正在为你生成。这就是为什么这么多代码。

文档通常会讨论用户的API,而不是存根内部方法。