Android - Pre-populated Database, insert or pre-loaded?

ε祈祈猫儿з 提交于 2021-01-27 12:31:32

问题


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.

  1. Run insert statements during oncreate of the database
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!