Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Data Storage with SQLite

Best practice for shipping a pre-populated DB ?

I need to include a non-trivial DB (~100MB), with an application since the data is not (and will not) be available on-line for downloading after installation.

This will mean wasting space since I'm forced to 1) Include it as a resource 2) re-created the DB to be able to work with it (resources are RO).

The two ways I've been considering (I've also implemented the first one since that was the least complex solution)

a) Include a full pre-created DB (possible compressed) as a resource and copy and install the DB into the proper DB directory.

b) Export the DB as SQL statements and include the statements as text-resource (possibly compressed) and run all the SQL statements after first install. Will take long time and also have additional complexity since the DB includes binary data (images) which needs to be handled (either as base64 in SQL or added as image resources)

Even with compression it still means a lot of wasted space in the resources (since the resource copy, as far as my investigation goes, cannot be deleted). But I cannot see any other way around this?

What is the best practice here?

Edit: One additional way I considered was to create a separate Db content provider app which is only used once (to read the DB from the real app) and can then be deleted by the user. This adds complexity since the user must install two apps (but since this will be a company private app it might not be a big issue) but no space is wasted at least.

Mazen Halawi
Mazen Halawi
7,806 Points

interesting topic! i would follow the first step if you dont intend to have a translated version of the app you are building, but if you do then the second approach will be best using string-resources will be very helpful, possibly creating an arraylist with trivia class like this ArrayList<Trivia> and that holds the question / possible answers / answer / picture resource.