androidserializationparcelablespanned

android: how to persistently store a Spanned?


I want to save a Spanned object persistently. (I'm saving the String it's based on persistently now, but it takes over 1 second to run Html.fromHtml() on it, noticeably slowing the UI.)

I see things like ParcelableSpan and SpannedString and SpannableString but I'm not sure which to use.


Solution

  • Right now, Html.toHtml() is your only built-in option. Parcelable is used for inter-process communication and is not designed to be durable. If toHtml() does not cover all the particular types of spans that you are using, you will have to cook up your own serialization mechanism.

    Since saving the object involves disk I/O, you should be doing that in a background thread anyway, regardless of the speed of toHtml().