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?
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);
}
Use TextUtils.writeToParcel()
method
Supporting spans in TextUtils
TextUtils
line 555-604
public static final int ALIGMENT_SPAN = 1;
......
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With