I have an object that i must save to file for reuse. The class of this object already implements Parcelable
for use in intents. My knowledge of saving an object to file says to implement Serializable
, but when i do, i get an error in the class that contains this object at the putExtra
method of an intent because both Serializable
and Parcelable
have this method.
Is there a way to avoid this, or just a way that i can save my object state and reload it easily?
I have looked at a few articles and i feel no more informed about how i should be saving my object. Thanks in advance
I believe that
Parcelable
andSerializable
both reaches the same goal in different ways and with different performances. Given that, if some class in your object hierarchy alread implements theParcelable
interface, you can override itswriteToParcel
method, call the super for it (so the members of the super classes will be written to the parcel if they were implement that way) and then, you should write your attributes to the parcel, always keeping in mind that the order you use to save them is the order you will use to retrieve them latter (FILO data structure)EDIT
Just cast your object where it complains and tells about the conflict to the class you want to use as described here: https://stackoverflow.com/a/13880819/2068693