0

I use Spannables with EditTexts.

So I want to store a object of Spannable to a file (or whatever the storage media) and retrieve it later.

(Don't reply with alternatives ways to store Spannable, I have tried most of them such as converting to html)

Is there a way to do this?

SadeepDarshana
  • 1,057
  • 18
  • 34
  • Check object serialization . http://stackoverflow.com/questions/4118751/how-do-i-serialize-an-object-and-save-it-to-a-file-in-android – Kiki Oct 09 '15 at 09:09
  • If you already did some research; why didn't you do prior research on the topic of your question? It is really not like you are the first person who things about storing his objects ... – GhostCat Oct 09 '15 at 09:14
  • Object serialization doesn't work here since *Spannable* is not serializable. – SadeepDarshana Oct 09 '15 at 09:52

1 Answers1

1

Yes, you can do with the use of Serialization. Read this page:

To serialize an object means to convert its state to a byte stream so that the byte stream can be reverted back into a copy of the object. A Java object is serializable if its class or any of its superclasses implements either the java.io.Serializable interface or its subinterface, java.io.Externalizable. Deserialization is the process of converting the serialized form of an object back into a copy of the object.

For example, the java.awt.Button class implements the Serializable interface, so you can serialize a java.awt.Button object and store that serialized state in a file. Later, you can read back the serialized state and deserialize into a java.awt.Button object.

This page has an example also. How to serialize and de-serialize an object.

And if you need a full code sniplet you can follow this-

I hpw this would help you.

Community
  • 1
  • 1
RajSharma
  • 1,941
  • 3
  • 21
  • 34
  • Object serialization doesn't work here since *Spannable* is not serializable. – SadeepDarshana Oct 09 '15 at 09:52
  • but how about extending a spannable and implementing serializable? – RajSharma Oct 09 '15 at 10:59
  • I tried to do that too, but whenever I use a class that is extended from SpannableStringsBuilder (i ddint even implement the serializing part yet) insted of SpannableStringsBuilder the app crashes. ( I tried to extend SpannableStringsBuilder without Spannable bcuz Spannable is an interface) – SadeepDarshana Oct 09 '15 at 11:36