Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write SpannableString to parcel?

In my application I have dialog which consists few SpannableString objects. Because this is dialog, I need to be able to store it when user leaves application and comes back to it later on.

But the problem is how can I write SpannableString into Parcel?

like image 628
Kandyzowana Papaja Avatar asked May 16 '15 10:05

Kandyzowana Papaja


2 Answers

I actually found out some way to do it using already existing functions, although I am not sure if it works for all type of spans, or just for those that I am using.

Inside write parcel methos you have to add

@Override
public void writeToParcel(Parcel dest, int flags) {
    TextUtils.writeToParcel(mSpannableString, dest, flags);
}

and next in order to extract SpannableString out of Parcel you should use this

public CustomConstructor(Parcel parcel) {
    mSpannableString = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
}
like image 153
Kandyzowana Papaja Avatar answered Oct 13 '22 01:10

Kandyzowana Papaja


Use TextUtils.writeToParcel() method

Supporting spans in TextUtils

TextUtils line 555-604 public static final int ALIGMENT_SPAN = 1; ......

like image 28
Jinsen 盛 Avatar answered Oct 13 '22 03:10

Jinsen 盛