user1178729
user1178729

Reputation:

Is it a good practice to serialize Parcelable objects for persistent storage?

I have two objects that implement the interface Item:

public interface Item extends Parcelable{//unneeded stuff}

I want to store an ArrayList<Item> persistently. Is making the Items Serializable a good practice?

Upvotes: 0

Views: 1276

Answers (3)

msh
msh

Reputation: 2770

Making object Serializable doesn't force you to use any particular serialization method. Generic Java serialization is quite inefficient, but nothing prevents you from making Serializable use Android parcelization (just marshal Parcel to the stream in writeObject)

But I doubt you really need serialization for data persistence. Shared preferences or database work better in most cases.

Upvotes: 0

user1270175
user1270175

Reputation: 233

Usually you make an object parcelable/serializable depending on your need. If you need that data to recreate your UI, pass into the bundle etc. then you would make it serializable.

Upvotes: 0

Joe Malin
Joe Malin

Reputation: 8641

Neither Parcelable nor Serializable are a good idea for persisting data. Store persistent data in SharedPreferences if possible, or wind it out to a file.

Serializable could hit you if you decide to change the structure of the object. Parcelable is not guaranteed to remain constant across versions; it's designed to pass data between processes, not store data.

If you want to store data long-term, you should write it to a file. Depending on how you want to access it, you may want to store it in a database or a content provider.

Upvotes: 1

Related Questions