问题
I am building an application which currently has 11 columns and 120~ rows of text data in one of its few tables. It will likely be the only table which is pre-populated for the user, however, I am trying to figure out what the best method is for populating the data. I see a few different options.
- Run insert statements during oncreate of the database
- Create a table in the assets folder which already has the data and copy it over when the application is created.
What is the best practice for something like this? 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.
Any help would be greatly appreciated.
回答1:
What is the best practice for something like this?
Option #2, specifically using SQLiteAssetHelper. It will be faster than executing SQL transactions and is easier as your pre-loaded contents get more complicated.
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 (i.e., will not be modified by your app at runtime based on user input), you have the option of distributing your updates via updates to the app itself. Otherwise, you will need to download the information for those changes and apply them, perhaps in response to a GCM message or a very occasional polling check.
来源:https://stackoverflow.com/questions/23273452/android-pre-populated-database-insert-or-pre-loaded