涉及到多进程通信时,常需要对相关类型的数据进程传递,常用方法为Intent或AIDL,且传递的对象基本要序列化(基本类型以及部分集合例外)。通过google的android开发文档,可知AIDL传递的数据主要支持以下几种类型:
- All primitive types in the Java programming language (such as
int
,long
,char
,boolean
, and so on) String
CharSequence
List
All elements in the
List
must be one of the supported data types in this list or one of the other AIDL-generated interfaces or parcelables you've declared. AList
may optionally be used as a "generic" class (for example,List<String>
). The actual concrete class that the other side receives is always anArrayList
, although the method is generated to use theList
interface.Map
All elements in the
Map
must be one of the supported data types in this list or one of the other AIDL-generated interfaces or parcelables you've declared. Generic maps, (such as those of the formMap<String,Integer>
are not supported. The actual concrete class that the other side receives is always aHashMap
, although the method is generated to use theMap
interface.
read CharSequence时采用方法:
<span style="font-family:FangSong_GB2312;font-size:18px;">data = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);</span>
write CharSequence时采用方法:
<span style="font-family:FangSong_GB2312;font-size:18px;">TextUtils.writeToParcel(data, destParcel, flags);</span>
这样处理后,就可以实现CharSequence类型的传递了