开发者

Distribute db with apk?

From the Dev Guide for using SQLite databases...

The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database.

Is this generally the 'only' way to do this or is it possible to include a pre-created empty (or even part populated) db with an apk distribution? Obviously, I can design my database on my PC and then just generate the 'CREATE TABLE' strings and cut/paste into my strings.xml but I w开发者_如何学编程as wondering about alternative approaches which might save the extra work.

EDIT: In light of KevinDTimm's answer, assuming this is possible, how do I include a pre-created SQLite db with my apk distribution? Any examples/pointers gratefully received.

Thanks.


The method I'm going to show you takes your own SQLite database file from the "assets" folder and copies into the system database path of your application so the SQLiteDatabase API can open and access it normally.

Have a look here : Using your own sqlite database in your Android applications


Do the latter. There is no reason to create on the fly if you already know the full structure (and possibly contents) of your db. One of the stated advantages of sqlite is potability of the db between platforms so make sure you utilize that strength whenever possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜