Deep.Timon
Deep.Timon

Reputation: 221

Android, Best way to store lists of data

I'm stuck on how I should go about storing some user data in my application I'm building.

The data being stored is effectively a list of items, like a list of car objects. The application must be able to store multiple lists.

Now i know there's several ways to store data, but I'm unsure what would be the best approach to storing these multiple lists.

so far i can only think of:

1) create table(s) for the lists.

2) storing each list as either a text file or xml file.

if anyone can explain what would be the best approach and if there are better alternatives what they would be.

Upvotes: 0

Views: 2338

Answers (1)

flx
flx

Reputation: 14226

There are basically a few options:

  1. Use a SQlite Database and optionally hide it behind a ContentProvider
  2. Let your Classes implement Serializable and save things with ObjectStream to some file to persist them
  3. Implement some custom String serialization (eg. JSONObject / JSONArray / XML) to save your objects in SharedPreferences

Pros/Cons:

  1. Quite an overhead but faster than the others when you got more than a couple of objects.
  2. Easy to implement, not that fast, OK for a couple objects
  3. Easy to implement, even slower, OK for a few objects, upgrading your data structure can break thinks. be prepared.

So in the end, it depends on your use case.

Further readings: https://developer.android.com/guide/topics/data/data-storage.html

Upvotes: 1

Related Questions