ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:26.15KB ,
资源ID:10576752      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10576752.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(使用AIDLAndroid接口描述语言设计和使用远程接口.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

使用AIDLAndroid接口描述语言设计和使用远程接口.docx

1、使用AIDLAndroid接口描述语言设计和使用远程接口使用AIDL(Android接口描述语言)设计和使用远程接口文章分类:移动开发 关键字: aidl、android 目录1 使用AIDL(AndRoid接口描述语言)设计和使用远程接口 1.1 使用AIDL实现IPC 1.1.1 创建一个AIDL文件 1.1.2 实现接口 1.1.3 向客户端公开接口 1.1.4 使用parcelables进行参数的值传递 1.2 调用一个IPC方法使用AIDL(AndRoid接口描述语言)设计和使用远程接口Since each application runs in its own process, a

2、nd you can write a service that runs in a different process from your Applications UI, sometimes you need to pass objects between processes. On the Android platform, one process can not normally access the memory of another process. So to talk, they need to decompose their objects into primitives th

3、at the operating system can understand, and marshall the object across that boundary for you.通常每个应用程序都在它自己的进程内运行,但有时需要在进程间传递对象,你可以通过应用程序UI的方式写个运行在一个不同的进程中的 service。在AndRoid平台中,一个进程通常不能访问其他进程中的内存区域。所以,他们需要把对象拆分成操作系统能理解的简单形式,以便伪装成对象跨越边界访问。The code to do that marshalling is tedious to write, so we prov

4、ide the AIDL tool to do it for you.编写这种伪装代码相当的枯燥乏味,好在我们提供了AIDL工具可以来做这件事。AIDL (Android Interface Definition Language) is an IDL language used to generate code that enables two processes on an Android device to talk using interprocess communication (IPC). If you have code in one process (for example,

5、in an Activity) that needs to call methods on an object in another process (for example, a Service), you would use AIDL to generate code to marshall the parameters.AIDL(AndRoid接口描述语言)是一个IDL语言,它可以生成一段代码,可以使在一个AndRoid设备上运行的两个进程使用内部通信进程进行交互。如果你需要在一个进程中(例如:在一个Activity中)访问另一个进程中(例如:一个Service)某个对象的方法,你就可以

6、使用 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或Corba类似,但它是轻量级的。它使用代理类在客户端和实现层间传递值。This page includes the following main topics:本页包含以

7、下主题:Implementing IPC Using AIDLCalling an .aidl (IPC) Class使用AIDL实现IPC调用一个AIDL(IPC)类使用AIDL实现IPCFollow these steps to implement an IPC service using AIDL.使用AIDL实现一个IPC有下列步骤:1.Create your .aidl file - This file defines an interface (YourInterface.aidl) that defines the methods and fields available to

8、a client.1、创建你的AIDL文件 - 这个文件定义一个接口(YourInterface.aidl),该接口定义了可供客户端访问的方法和属性。2.Add the .aidl file to your makefile - (the Eclipse plugin manages this for you). Android includes the compiler, called AIDL, in the tools/ directory.2、添加AIDL文件到你的makefile中-(Eclipse plugin可以帮你管理)。AndRoid包括编译器,AIDL调用,这些都能在too

9、ls/directory中找到。3.Implement your interface methods - The AIDL compiler creates an interface in the Java programming language from your AIDL interface. This interface has an inner abstract class named Stub that inherits the interface (and implements a few additional methods necessary for the IPC call

10、). You must create a class that extends YourInterface.Stub and implements the methods you declared in your .aidl file.3、实现接口方法-AIDL编译器从你的AIDL接口中使用JAVA编程语言来创建一个接口。这个接口有一个名为Stub的内部抽象类,它继承接口(并实现供IPC调用的所必需的几个附加方法)。你必须创建一个类来实现该接口。4.Expose your interface to clients - If youre writing a service, you should

11、 extend Service and override getBinder() to returning an instance of your class that implements your interface.4、向客户端开放接口-如果你写个service,你应该扩展该Service并重载getBinder()方法来返回一个实现上述接口的类的实例。编辑 创建一个AIDL文件AIDL is a simple syntax that lets you declare an interface with one or more methods, that can take paramet

12、ers and return values. These parameters and return values can be of any type, even other AIDL-generated interfaces. However, it is important to note that you must import all non-built-in types, even if they are defined in the same package as your interface. Here are the data types that AIDL can supp

13、ort:AIDL语法简单,你可以用来声明一个带一个或多个方法的接口,也可以传递参数和返回值。这些参数和返回值可以是任何类型,甚至是其他的AIDL 生成的接口。然而,值得重视的是你必须导入所有的non-bult-in类型,即使他们已经作为接口在其他包里定义了。下面是些AIDL支持的数据类型:Primitive Java programming language types (int, boolean, etc) No import statement is needed.简单Java编程语言类型(int,boolean等) -不需要import声明。One of the following cl

14、asses (no import statements needed):下面类之一(不需要import声明)Java 代码 1. .String 2. .List - All elements in the List must be one of the types in this list, including other AIDL-generated interfaces 3. and parcelables. List may optionally be used as a generic class (e.g. List). The actual concrete class 4. t

15、hat the other side will receive will always be an ArrayList, although the method will be generated to use the 5. List interface. 6. .List - List 中的所有元素都必须是可支持的类型中的一个,包括其他AIDL生成接口和parcelables。List可以作为泛型类来灵活使用(比如 7. List)。 而实际的接受方的类则总是ArrayList,尽管该方法将被生成来使用List接口。 8. .Map - All elements in the Map mus

16、t be of one of the types in this list, including other AIDL-generated interfaces 9. and parcelables. Generic maps, (e.g. of the form Map are not supported. The actual concrete class 10. that the other side will receive will always be a HashMap,although the method will be generated to use the Map int

17、erface. 11. .Map - Map 中的所有元素都必须是可支持的类型中的一个,包括其他AIDL生成接口和parcelables。泛型化的Maps(比如:Map)不被支持。 12. 而实际的接受方的类则总是 HashMap,尽管该方法将被生成去使用Map接口。 13. .CharSequence - This is useful for the CharSequence types used by TextView and other widget objects. 14. .CharSequence - CharSequence 的作用是可以被TextView和其他Widget对象使

18、用。 .String .List - All elements in the List must be one of the types in this list, including other AIDL-generated interfaces and parcelables. List may optionally be used as a generic class (e.g. List). The actual concrete class that the other side will receive will always be an ArrayList, although t

19、he method will be generated to use the List interface. .List - List中的所有元素都必须是可支持的类型中的一个,包括其他AIDL生成接口和parcelables。List可以作为泛型类来灵活使用(比如 List)。而实际的接受方的类则总是ArrayList,尽管该方法将被生成来使用List接口。.Map - All elements in the Map must be of one of the types in this list, including other AIDL-generated interfaces and p

20、arcelables. Generic maps, (e.g. of the form Map are not supported. The actual concrete class that the other side will receive will always be a HashMap,although the method will be generated to use the Map interface. .Map - Map中的所有元素都必须是可支持的类型中的一个,包括其他AIDL生成接口和parcelables。泛型化的Maps(比如:Map)不被支持。 而实际的接受方

21、的类则总是HashMap,尽管该方法将被生成去使用Map接口。.CharSequence - This is useful for the CharSequence types used by TextView and other widget objects. .CharSequence - CharSequence的作用是可以被TextView和其他Widget对象使用。Other AIDL-generated interfaces, which are always passed by reference. An import statement is always needed for

22、 these. Custom classes that implement the Parcelable protocol and are passed by value. An import statement is always needed for these.其他的AIDL生成接口通过引用方式进行传递。所以import声明是必须的。封装协议实现的自定义的类是值传递的方式。所以import声明也是必须的。Here is the basic AIDL syntax:下面是基本的AIDL语法:Java 代码 1. / My AIDL file, named SomeClass.aidl 2.

23、 / Note that standard comment syntax is respected. 3. / Comments before the import or package statements are not bubbled up 4. / to the generated interface, but comments above interface/method/field 5. / declarations are added to the generated interface. 6. / Include your fully-qualified package sta

24、tement. 7. package com.google.android.sample; 8. / See the list above for which classes need 9. / import statements (hint-most of them) 10. import com.google.android.sample.IAtmService; 11. / Declare the interface. 12. interface IBankAccountService 13. / Methods can take 0 or more parameters, and 14

25、. / return a value or void. 15. int getAccountBalance(); 16. void setOwnerNames(in List names); 17. / Methods can even take other AIDL-defined parameters. 18. BankAccount createAccount(in String name, int startingDeposit, in IAtmService atmService); 19. / All non-Java primitive parameters (e.g., int

26、, bool, etc) require 20. / a directional tag indicating which way the data will go. Available 21. / values are in, out, inout. (Primitives are in by default, and cannot be otherwise). 22. / Limit the direction to what is truly needed, because marshalling parameters 23. / is expensive. 24. int getCus

27、tomerList(in String branch, out String customerList); 25. / My AIDL file, named SomeClass.aidl/ Note that standard comment syntax is respected./ Comments before the import or package statements are not bubbled up/ to the generated interface, but comments above interface/method/field/ declarations ar

28、e added to the generated interface./ Include your fully-qualified package statement.package com.google.android.sample;/ See the list above for which classes need/ import statements (hint-most of them)import com.google.android.sample.IAtmService;/ Declare the interface.interface IBankAccountService /

29、 Methods can take 0 or more parameters, and / return a value or void. int getAccountBalance(); void setOwnerNames(in List names); / Methods can even take other AIDL-defined parameters. BankAccount createAccount(in String name, int startingDeposit, in IAtmService atmService); / All non-Java primitive

30、 parameters (e.g., int, bool, etc) require / a directional tag indicating which way the data will go. Available / values are in, out, inout. (Primitives are in by default, and cannot be otherwise). / Limit the direction to what is truly needed, because marshalling parameters / is expensive. int getCustomerList(in String branch, out String customerList);实现接口AIDL generates an interface file for you with the same name as your .aidl file. If you are using the Eclipse plugin, AIDL will aut

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1