简体   繁体   English

Android 远程服务使用aidl

[英]Android remote service using aidl

I'm trying to create a remote service in Eclipse using Android AIDL.我正在尝试使用 Android AIDL 在 Eclipse 中创建远程服务。 I have created my AIDL file IRemoteService.aidl in /src as follows:我在 /src 中创建了我的 AIDL 文件 IRemoteService.aidl,如下所示:

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

After doing a build I get an enormous file IRemoteService.java in /gen containing these classes and methods as follows (it doesn't resemble anything I've seen in the documentation):构建完成后,我在 /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;

So why does IRemoteService.java contain so much junk not mentioned in the documentation?那么为什么 IRemoteService.java 包含这么多文档中没有提到的垃圾? How could I possibly know what to do with it all?我怎么可能知道如何处理这一切? How could I possibly know what to do with any of it?我怎么可能知道如何处理它?

This is service stub code.这是服务存根代码。 It is needed to actually communicate with client.需要与客户进行实际通信。 You didn't write any code for communicating between client and service yourself,did you?您自己没有编写任何用于在客户端和服务之间进行通信的代码,是吗? It's not as simple, after all and it is being generated for you.毕竟它不是那么简单,它是为你生成的。 That's why so much code.这就是为什么这么多代码。

And documentation usually discusses API for user, not stub internal methods.文档通常为用户讨论 API,而不是存根内部方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM