[英]What's the best practice when populating a sqlite database with default data?
I'm making an app that will be using few hundred database posts from a sqlite database. 我正在制作一个将使用sqlite数据库中的数百个数据库帖子的应用程序。 I will not be adding new data during the lifetime of the app (unless I update the whole app). 在应用程序的生命周期内,我不会添加新数据(除非我更新整个应用程序)。
I might end up using a static xml for the data, but I need to flag posts, so I guess a sqlite db would do the job best. 我可能最终会使用静态xml来存储数据,但是我需要标记帖子,所以我猜sqlite db会做得最好。 I know how to implement it and I've released apps using sqlite before... 我知道如何实现它,并且之前我已经使用sqlite发布了应用...
But my question is. 但是我的问题是。 How to I best populate the sqlite db the first time the app runs? 如何在应用程序首次运行时最好地填充sqlite数据库? Should I just bring in a file that I use as a resource and then copy to the apps space? 我是否应该引入一个用作资源的文件,然后复制到应用程序空间? What's the best/easiest practice? 最佳/最简便的做法是什么?
The simplest solution is to use SQLiteAssetHelper
. 最简单的解决方案是使用SQLiteAssetHelper
。 You basically drop your SQLite database into your project's assets/
directory, and use SQLiteAssetHelper
in lieu of SQLiteOpenHelper
. 基本上,您将SQLite数据库放入项目的assets/
目录中,并使用SQLiteAssetHelper
代替SQLiteOpenHelper
。 In addition to the sample code up on Jeff Gilfelt's GitHub repo for the library, I have a sample app demonstrating it as well. 除了在Jeff Gilfelt的GitHub存储库上提供示例代码外,我还有一个示例应用程序对其进行演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.