Alan Moore
Alan Moore

Reputation: 6575

What is the best way to store an array of objects persistent?

I have an array of objects in my Android app which I would like to store persistently. The options I'm aware of are:

  1. Store in a db -- sqlite
  2. Store in a file -- like in XML
  3. Store in SharedPreferences

I really want the simplest and cleanest implementation. Is #3 even feasible? I haven't found any discussion of that, although that is the solution I used on my iPhone version of the app.

Upvotes: 0

Views: 357

Answers (1)

acjay
acjay

Reputation: 36641

In Java, the trick is to implement the interface Serializable. As long as the entire object graph you're trying to serialize contains only objects that also implement Serializable, the default serialization algorithm can use reflection to generate the byte stream for you, and you can output it to anything that can accept a byte stream

Upvotes: 1

Related Questions