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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值