Load large amount of data to DB - Android

给你一囗甜甜゛ 提交于 2019-12-23 01:14:28

问题


I'm building a new application to the Android platform and I need a suggestion. I have a large amount of data that I want to import into a sqlite DB, something like 2000 rows. My question is what is the best method to load the data into the DB?

Two ways I think of:

  1. An xml file that holds all the data and then loads it with DocumentBuilder object.
  2. A CSV file, and loads it with String Tokenizer. Found that post.

I want it to be with external file because When I release an update I will replace only the that file.

I want something that would be efficient as much as possible - all the data will load at the first startup of the application and I need it to be fast.

Any suggestion would be great. Thanks.


回答1:


Use InsertHelper to do a bulk insert. Take a look on this other question




回答2:


Instead of XML or CSV files, you can directly use an external sqlite DB you prepared in your computer. This technique is explained here: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/




回答3:


It really does not matter - you can achieve good perfomance with both approaches. With XML you can use some databinding, making programming easier (marginally). You may also consider JSON as transport format.

When parsing, keep in mind that building complete object tree in memory ( like XML DOM parser) consumes a lot of memory and results in a lot of allocations - pull parsing model like XPP / GSON is preferable.



来源:https://stackoverflow.com/questions/10840117/load-large-amount-of-data-to-db-android

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