0

What is the best way to store lots of static objects in an android app?

It's for a reference app. An object can have many children.

A database would be good, but then I have to initialize all the content from it from a bunch of inserts when the app is installed, and this results in kind of having the information twice in the app storage (A large amount of inserts, and the database information). I found some workarounds of having set the initial db with the content pre-populated but it seems is not a good practice in general.

I think I cannot use the strings.xml file as I cannot create complex objects there (for example the children which vary in quantity depending of the object).

What would be the best approach to storing and accessing this objects?

adrianrdzv
  • 125
  • 1
  • 12
  • This will quickly be question about performance vs memory, you need to provide more info, do you need it to be super quick or is that no concern? – Warpzit Aug 14 '12 at 08:20
  • It doesn't need to be super quick. Let's say there are a 200 places and within each one of them there area 50 children. Within the app you navigate and search from top to bottom (from parents to children). – adrianrdzv Aug 14 '12 at 08:29

1 Answers1

1

You CAN define all of these in XML, it may be rather large and complex XML, but it can be done. Though XML is good for initial storage and data replication, it is NOT good for (fast and frequent) data access.
If you have a large and complex data structure which you need to access frequently AND speed is important than probably your only option is DB.
So, store the initialisation data in XML, initialise DB once and run your app from DB.
If the number of objects is NOT very high than you may be able to use in-memory-DB that will improve performance a lot.
Another option: you can have central DB available on-line and application connecting to remote on-line central DB to obtain initialisation data.

Germann Arlington
  • 3,315
  • 2
  • 17
  • 19