[英]Which file type should I use to store database data
I'm developing a little Android app which is going to be offline, and I need to store the SQLite base's data into a file, that I want to put into the apk's resources, I could use XML or JSON files, but I was wondering if there weren't a better solution. 我正在开发一个小型Android应用程序,该应用程序将脱机,并且需要将SQLite基础数据存储到文件中,我想将其放入apk的资源中,我可以使用XML或JSON文件,但是我想知道如果没有更好的解决方案。
Thanks in advance :) 提前致谢 :)
If I understand you right you have some prepared data to include in app to use. 如果我了解您的权利,那么您可以在应用程序中包含一些准备使用的数据。
If you don't want to parse xml, json or raw file every time you need it in the app you could: 如果您不想每次在应用程序中需要时都解析xml,json或原始文件,则可以:
1. Parse the file and put contents into SQLite database on the first run of the app. 1.在应用程序的第一次运行时,解析文件并将内容放入SQLite数据库。
Then you can use SQLite to query for data. 然后,您可以使用SQLite查询数据。
You can check if this is first run by checking boolean flag in SharedPreferences upon start of application (in onCreate of your main activity or in Application class) 您可以通过在应用程序启动时(在您的主要活动的onCreate或Application类中)在SharedPreferences中检查布尔值标志来检查是否首先运行它
2. If data is not very big you could parse it once and keep it in memory in your custom data structure. 2.如果数据不是很大,则可以解析一次并将其保存在自定义数据结构的内存中。
You can create a singleton to query for this data and parse it in case it is not loaded yet. 您可以创建一个单例查询此数据,并在尚未加载数据时对其进行解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.