简体   繁体   English

我应该使用哪种文件类型存储数据库数据

[英]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.

相关问题 我应该使用哪种类型的数据库? - Which type of database should I use? 我应该将MVVM的哪一部分存储在数据库中 - Which part of MVVM i should be store data in database 我应该使用哪个数据库? - which database should I use? 我应该使用哪种类型的服务进行数据迁移? - Which type of service should I use for data migration? 我应该使用哪种类型的Android服务? - Which type of Android Services should I use? 我应该使用哪种格式在Android App SQLite数据库中存储日期和时间,以便可以使用它们来绘制图形? - Which format should I use to store dates and times in an Android App SQLite Database, such that I can use them to plot a graph? 我应该使用SQLiteDatabase来存储数据吗? - Should I use SQLiteDatabase to store data? 我应使用哪种方法为Android应用程序存储和检索图像? - Which method should I use to store and retrive images for an android application? 我应该将哪个 firebaseUI 库用于 androidX 中的实时数据库? - Which firebaseUI library should I use for the realtime database in androidX? 我应该使用哪种布局来在 android 中制作表格类型的布局? - which layout should i use for making a table type layout in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM