CharSequence类型数据跨进程传递

涉及到多进程通信时,常需要对相关类型的数据进程传递,常用方法为Intent或AIDL,且传递的对象基本要序列化(基本类型以及部分集合例外)。通过google的android开发文档,可知AIDL传递的数据主要支持以下几种类型:

  • All primitive types in the Java programming language (such as intlongcharboolean, 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. A List may optionally be used as a "generic" class (for example, List<String>). The actual concrete class that the other side receives is always an ArrayList, although the method is generated to use the List 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 form Map<String,Integer> are not supported. The actual concrete class that the other side receives is always a HashMap, although the method is generated to use the Map interface.

尽管CharSequence类型属于AIDL支持的类型,但是在read和write方法中却没有提供相应的方法,查阅许多博文,也均没有说到如何实现CharSequence传递。通过阅读源码才知道其处理逻辑如下:

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类型的传递了

你可能感兴趣的:(aidl,多进程通信,CharSequence类型)