开发者

Android SQLite DB Question

开发者 https://www.devze.com 2023-01-18 21:21 出处:网络
I have a question about when you distribute your app with an existing DB. Right now I\'ve created a basic app, and from my understanding, the .db file should be in the assets folder, and when the use

I have a question about when you distribute your app with an existing DB.

Right now I've created a basic app, and from my understanding, the .db file should be in the assets folder, and when the user first runs your app it should check if the DB exists in the \data\data\ folder, if it's not there it should copy it over...correct?

My question is, what about updates? When the user downloads an update to said app, we'll need to insert a more rows into a couple specific tables (I think there's about 8 tables in total). How should this be handled? Should the DB be overwritten completely or is there a way copy over the differences?

Thanks 开发者_StackOverflow社区for your help! Sorry if it sounds a bit confusing.


This can be handled for you by SQLiteOpenHelper.onUpgrade.

You can read the Notepad tutorial if you want to see an example in action.


I have some data that I distribute with my app. Instead of shipping a binary DB, I just ship a static JSON file that is included in the app and load the data into a blank DB on the first run. That way I can more easily update the initial values that are stored in the database.

0

精彩评论

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