Java – Android – Pre-populate database, insert or preload?

Android – Pre-populate database, insert or preload?… here is a solution to the problem.

Android – Pre-populate database, insert or preload?

I’m building an app that currently has 11 columns and 120~ rows of text data in one of its several tables. It may be the only table pre-populated for the user, however, I’m trying to figure out the best way to populate the data. I see a couple of different options.

  1. Run insert statements during database creation
  2. Create a table in the Assets folder where you already have the data and copy it
    When you create an application.

What is the best practice for something like this? Over time, the database will be updated with more rows. I might look at a few lines a month, not too big.

Any help would be appreciated.

Solution

What is the best practice for something like this?

Option #2, specifically using SQLiteAssetHelper. And easier as preloaded content becomes more complex.

Over time, the database will be updated with a few more rows. I am looking at maybe a few rows a month, nothing too big.

If the database is purely read-only (that is, your app doesn’t modify based on user input at runtime), you can choose to distribute the updates through updates to the app itself. Otherwise, you will need to download the information for these changes and apply them, perhaps in response to a GCM message or a very occasional polling check.

Related Problems and Solutions