AIDL API级别详细解释

AIDL 就是android interface definition language。官方API如是解释。

(以下所有东西,我挑重点翻译)

1.AIDL (Android Interface Definition Language) is similar to other IDLs you might have worked with. It allows you to define the programming interface that both the client and service agree upon in order to communicate with each other using interprocess communication (IPC). On Android, one process cannot normally access the memory of another process. So to talk, they need to decompose their objects into primitives that the operating system can understand, and marshall the objects across that boundary for you. The code to do that marshalling is tedious to write, so Android handles it for you with AIDL.

这段话说的是啥意思?

AIDL和其他你用过的IDL很类似,这个东西允许你在客户端和服务端定义的程序接口,这两个接口通过IPC达成协议来完成对彼此的通信。在android程序中,一个程序不能正常的访问另一个程序。所以呢,他们需要暴露他们的工程到编译系统能识别的原始状态,然后安排两个程序为你打破自己的边界。这个实现的代码很无聊,所以android使用AIDL实现这些功能。

Before you begin designing your AIDL interface, be aware that calls to an AIDL interface are direct function calls. You should not make assumptions about the thread in which the call occurs. What happens is different depending on whether the call is from a thread in the local process or a remote process. Specifically:

在你定义你的AIDL之前,你必须知道AIDL是接口是直接方法的调用,你不能对在线程中的AIDL调用做出推断和假设。它的表现形式在本地进程中的某个线程或这远程进程中是不同的,具体如下:

1.Calls made from the local process are executed in the same thread that is making the call. If this is your main UI thread, that thread continues to execute in the AIDL interface. If it is another thread, that is the one that executes your code in the service. Thus, if only local threads are accessing the service, you can completely control which threads are executing in it (but if that is the case, then you shouldn't be using AIDL at all, but should instead create the interface by implementing a Binder).

1.本地进程中的调用是在同一个线程中执行的。如果这是你的主UI线程,这个线程在AIDL接口中继续执行。如果是另一个线程,那就是在服务中执行你的代码的那个。这样,如果只有本地线程访问service,你可以完全控制线程在哪个里面执行(如果是另一种情况,你不能使用AIDL,你应该使用实现Binder的接口代替AIDL)。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值