9

I'm writing an application which needs to store data. A single pack of data is about 4 classes with many dependencies between them. For example, class A has a list of objects B and B has a list of objects C and few more dependencies...

And I wonder what would be better. Keep them in SQLite db or serialize each pack separately and store them in serialized files?

Junuxx
  • 14,011
  • 5
  • 41
  • 71
Michal W
  • 793
  • 8
  • 24
  • 5
    If anyone cares i choosed serialization : P – Michal W Nov 05 '12 at 21:32
  • 1
    You should really [not use Serialization in Android](http://stackoverflow.com/questions/3611843/is-using-serializable-in-android-bad). I suggest you check [GSON](http://code.google.com/p/google-gson/). – m0skit0 Apr 18 '13 at 15:24

2 Answers2

3

For me the only right solution would be to save the data inside a database especially if there are any dependencies. For beginners it might be hard at the beginning to get into database creation. but after you have created a database in the right form you just have to insert the data and you won't have any problems in the future if you want to change something or expand your app. With simple serialisation the logic has to be solved inside the app and might cause more problems especially if you have any dependencies.

If you need a good tutorial for saving data you should look at this tutorial http://thenewboston.org/watch.php?cat=6&number=111

For other different solutions for saving data there are also some tutorials on the website, Nr. 108 - 110 of Android programming

Pi Delport
  • 10,356
  • 3
  • 36
  • 50
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
1

IT depends on the usage of the data. You may do well choosing JSON/GSON serialization and avoid the overhead of doing ORM over SQLite. (Overhead meaning additional coding to marshall to/from the db) However, if your data is subject to growth or something that would be better managed by a db (a lot of non-sequential or random access across a larger data set) then go for SQLite and ORM. In the end it comes down to what type of data you are trying to manage. Again if your data set is something that could grow and involves a lot of random access it may be worth using SQLite.

Cliff
  • 10,586
  • 7
  • 61
  • 102