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

前端之家收集整理的这篇文章主要介绍了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);
原文链接:https://www.f2er.com/android/310755.html

猜你在找的Android相关文章