Dev Guide_01_AIDL/IPC机制

Designing a Remote Interface Using AIDL

In this document

  1. Implementing IPC Using AIDL
    1. Create an .aidl File
    2. Implementing the Interface
    3. Exposing Your Interface to Clients
    4. Pass by value Parameters using Parcelables
  2. Calling an IPC Method

Since each application runs in its own process, and you can write a service thatruns in a different process from your Application's UI, sometimes you need to pass objectsbetween processes. On the Android platform, one process can not normally access the memoryof another process. So to talk, they need to decompose their objects into primitives thatthe operating system can understand, and "marshall" the object across that boundary for you..

 

个人理解: 通常每个应用程序都在它自己的进程内运行,但有时需要在进程间传递对象,你可以通过Application's UI的方式写个运行在一个不同的进程中的service。注意:service运行在主线程当中,除非你自己在开启一个线程来运行service。
android平台中,一个进程通常不能访问其他进程中的内存区域。所以,他们需要把对象拆分成操作系统能理解的简单形式/基本单元,以便伪装成对象跨越边界访问。

 

The code to do that marshalling is tedious to write, so we provide the AIDL tool to do itfor you.

 

个人理解: 编写这种伪装代码相当的枯燥乏味,所以android为我们提供了AIDL工具。


AIDL (Android Interface Definition Language) is an IDLlanguage used to generate code that enables two processes on an Android-powered deviceto talk using interprocess communication (IPC). If you have codein one process (for example, in an Activity) that needs to call methods on anobject in another process (for example, a Service), you would use AIDL togenerate code to marshall the parameters.

 

个人理解:AIDL是一种接口定义语言,他可以使能在Android-powered device(android设备)上运行的两个进程用IPC去通信。如果你需要在一个进程中(例如:在一个Activity中)访问另一个进程中(例如:一个Service)某个对象的方法,你就可以使用AIDL来生成这样的代码来伪装传递各种参数。


The AIDL IPC mechanism is interface-based, similar to COM or Corba, but lighter weight. It uses a proxy class to pass values between the client and the implementation.

 

个人理解:AIDL IPC机制是基于接口的,类似于 COM or Corba,但是比这两者还要轻量级。它使用代理类在客户端之间传递、实现值。

 

重要说明:


1. 本人不才,欢迎批评指正!关于这篇文档的相关内容,可以参阅文档,很简单的。仁者见仁智者见智吧,看英文需要耐心..祝您开发顺利。


2. android的Service不是一个单独的进程它和主线程在同一个进程,也不是应用程序开启(spawn)的一个新线程它是主线程的一部分。它运行在主线程当中,如果要在服务中操作一些比较耗时的工作,可以考虑开启线程!





©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页