使用默认数据填充 sqlite 数据库时的最佳做法是什么?

What's the best practice when populating a sqlite database with default data?

我正在制作一个应用程序,它将使用来自 sqlite 数据库的数百个数据库帖子。我不会在应用程序的生命周期内添加新数据(除非我更新整个应用程序)。

我最终可能会为数据使用静态 xml,但我需要标记帖子,所以我想 sqlite 数据库会做得最好。我知道如何实现它并且我之前发布过使用 sqlite 的应用程序...

但我的问题是。如何在应用程序第一次运行时最好地填充 sqlite 数据库?我是否应该只引入一个我用作资源的文件,然后复制到应用程序 space? best/easiest 做法是什么?

最简单的解决方案是 use SQLiteAssetHelper. You basically drop your SQLite database into your project's assets/ directory, and use SQLiteAssetHelper in lieu of SQLiteOpenHelper. In addition to the sample code up on Jeff Gilfelt's GitHub repo for the library, I have a sample app 也进行演示。