`
pipisky
  • 浏览: 2310 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

Passing Complex Types to Services

阅读更多
Passing complex types to and from services requires more work than passing Java primitive types. Before embarking on this work, you should get an idea of AIDL’s support for nonprimitive types:
1.  AIDL supports String and CharSequence.
2.  AIDL allows you to pass other AIDL interfaces, but you need to have
an import statement for each AIDL interface you reference (even if the
referenced AIDL interface is in the same package).
3.  AIDL allows you to pass complex types that implement the
android.os.Parcelable interface. You need to have an import
statement in your AIDL file for these types.
4.  AIDL supports java.util.List and java.util.Map, with a few
restrictions. The allowable data types for the items in the collection
include Java primitive, String, CharSequence, or
android.os.Parcelable. You do not need import statements for List
or Map, but you do need them for the Parcelables.
5.  Nonprimitive types, other than String, require a directional indicator. Directional indicators include in, out, and inout. in means the value is set by the client, out means the value is set by the service, and inout means both the client and service set the value.
The Parcelable interface tells the Android runtime how to serialize and deserialize objects during the marshalling and unmarshalling process.
与services交换复杂数据比传递基本类型需要更大的工作量。在开始这个工作之前,我们需要熟悉一下AIDL所支持的非java基本类型:
1,String和CharSequence
2,AIDL interfaces(需要有个你引入的interface的import,即使在一个包中)
3,实现了android.os.Parcelable接口的复杂类型。需要import
4,java.util.List和java.util.Map,但稍有些限制。集合中的类型只能是java基本类型,String,CharSequence,或者是android.os.Parcelable。可以不用import List或者Map, 但一定要有Parcelables的import。
5,非基本类型,不同于String,需要directional indicator(方向的指示)。方向的指示包括in,out and inout。 in标示client设置value, out标示service设置value, inout标示client和service都设置value。
Parcelable interface 告诉android运行时如何序列化和反序列化对象在数据封送处理和数据分解过程中。


To properly implement an object for interprocess communication, we have to do the following:
1. Implement the Parcelable interface. This means that you implement
writeToParcel() and readFromParcel(). The write method will write
the object to the parcel and the read method will read the object from
the parcel. Note that the order in which you write properties must be
the same as the order in which you read them.
2. Add a static final property to the class with the name CREATOR. The
property needs to implement the android.os.Parcelable.Creator<T>
interface.
3. Provide a constructor for the Parcelable that knows how to create the object from the Parcel.
4. Define a Parcelable class in an .aidl file that matches the .java file containing the complex type. The AIDL compiler will look for this file when compiling your AIDL files.
为了实现跨进程的通信,我们需要做如下的工作:
1,实现parcelable接口,wirteToParcel()和readFromParcel()方法。需要注意的是写入属性和读取必须是同一个次序。
2,添加一个名称为CREATOR的静态常量,他的属性为android.os.Parcelable.Creator<T> interface.
3,提供一个构造函数
4,定义一个Parcelable的类在.aidl文件中。

待续。。。
分享到:
评论
1 楼 王山而 2010-07-10  
受益匪浅》》》》

相关推荐

    ROS By Example A Do It Yourself Guide to the Robot Operating System.pdf

    ROS is not an operating system in the traditional sense but rather a middleware that provides services designed for a heterogeneous computer cluster such as hardware abstraction, device drivers, ...

    Beginning Microsoft Visual CSharp 2008 Wiley Publishing(english)

    Complex Variable Types 140 String Manipulation 155 Summary 160 Exercises 161 Chapter 6: Functions 162 Defining and Using Functions 163 Variable Scope 175 The Main() Function 181...

    GWT in Action

    It provides a comprehensive set of tools and libraries that facilitate the creation of complex user interfaces and robust back-end services. **GWT in Action** is a comprehensive guide that covers all...

    Beginning PHP 5.3

    - **Nested Control Structures:** Discussion on nesting control structures to create more complex logic. - **Flow Control Functions:** Introduction to functions like `break` and `continue` for ...

    Microsoft Library MSDN4DOS.zip

    Chapter 5 Defining and Using Complex Data Types Chapter 6 Using Floating-Point and Binary Coded Decimal Numbers Chapter 7 Controlling Program Flow Chapter 8 Sharing Data and Procedures among Modules ...

    数位板压力测试

    The interface should accommodate three kinds of programmers: those who wish to write sim-ple tablet programs, programmers who wish to write complex applications that take full ad¬vantage of tab-let ...

    The Art of Assembly Language Programming

    QWORD, and TBYTE Variables 5.3.5 - Declaring Floating Point Variables with REAL4, REAL8, and REAL10 5.4 - Creating Your Own Type Names with TYPEDEF 5.5 - Pointer Data Types 5.6 - ...

    python3.6.5参考手册 chm

    PEP 529: Change Windows filesystem encoding to UTF-8 PEP 528: Change Windows console encoding to UTF-8 PEP 520: Preserving Class Attribute Definition Order PEP 468: Preserving Keyword Argument ...

Global site tag (gtag.js) - Google Analytics