我想能够将我的一个应用程序活动的格式化文本(即格式跨度的文本)发送到另一个应用程序.这些CharSequence实例深入我创建的一些Parcelable类型.
例如,当编组携带格式化CharSequences的类型之一时,我使用TextUtils.writeToParcel如下:
public class HoldsCharSequence { /* some formatted string that uses basic spans (e.g.,ForegroundColorSpan) */ private CharSequence cs; public void writeToParcel(Parcel out,int flags) { TextUtils.writeToParcel(cs,out,0); } /* ... rest of the code ... */ }
问题是我不知道如何从我的私有构造函数中的包裹中检索CharSequence.
以下不起作用:
private HoldsCharSequence(Parcel in) { cs = (CharSequence) in.readValue(CharSequence.class.getClassLoader()); }
我收到以下错误:
android.os.BadParcelableException: ClassNotFoundException when unmarshalling
还有两件事:
我已经成功地实现了我自己定制的Parcelable对象,特别是CharSequences的问题.
我知道TextUtils.writeToParcel将尽一切努力保存文本格式,我可以与之一起生活.