android – 如何从包裹检索使用TextUtils.writeToParcel(…)保存的CharSequence?

我想能够将我的一个应用程序活动的格式化文本(即格式跨度的文本)发送到另一个应用程序.这些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将尽一切努力保存文本格式,我可以与之一起生活.

解决方法

如果有人有兴趣,我会在 this post发现答案.

使用TextUtils.writetoParcel(…)检索存储在宗地中的CharSequences的正确方法

cs = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...