1

this is the first time that I need to store some data permanently so I would like some suggestions before to proceed. I've read that there are different ways to store data on an Android device:

  • Internal storage
  • Shared Preference (but if I've understood is just for symple data like an option)
  • Shared storage (but I don't need to share data among other apps)
  • Database

I can't understand what is the best option for me between the first and the last.

My case

I have a list of book with title, subtitle, cover image and each book contains a list of cards with title, optional image, (audio if possible), other stuff.

So, I have to store an arraylist of a custom class that includes another arraylist of anothercustomclass and some text/image

Which approach should I take?

Thanks

patana93
  • 73
  • 1
  • 8

1 Answers1

1

Frankly, the case description is much too limited to give an informed advice (so the question should be closed).

But if you have doubts, then the safe / default choice is the database. It might come with big overhead for some cases (like when it's enough to serialize the whole arraylist to a blob and store as a single file), but you are less likely to paint yourself into a corner.

Addition (after a comment)

When using a database, you don't store objects directly (because what an sql database stores are "relations" which you can think of as "sets of rows", not objects). Instead you have some code (custom or from a library) that translates an object into a row (or multiple rows) for storage and some code that translates it the other way.

If you want to store the actual objects, then serialization to a file is pretty much the only way.

fdreger
  • 12,264
  • 1
  • 36
  • 42
  • Ok so I will search how to store my classes in a local database (sql). Thanks anyway for your help! – patana93 Jan 03 '21 at 15:07
  • 1
    @CarloPalumbo extended the answer. A bit of a nickpick, but it's not "storing classes", but "storing objects". When a Java programmer says: "I need to store some classes" they mean either the Java code itself (in the compiled form) or instances of the `Class` object - neither of which is what you want to do. – fdreger Jan 04 '21 at 07:53