开发者

android sqlite on application update

开发者 https://www.devze.com 2023-04-13 00:54 出处:网络
I hava an android application which consists sqlite database in the assets folder. In the DB I have several tables, which one of them is user data (which is updated over time by using the application

I hava an android application which consists sqlite database in the assets folder. In the DB I have several tables, which one of them is user data (which is updated over time by using the application - when the user installs the application this table is empty). The other tables store data that I update.

The question is: when a user gets an updated version of my application (with sqlite database in the assets folder) from the market, I need to keep the data the user updated by using the application, but i do want to update the other tab开发者_开发问答les (which consist my data).

What is the correct way to do it?

Thank You :)


Keep a version number for each change and implement the onUpgrade method for the possible combinations. See more in the javadoc for SQLiteOpenHelper


Since you said your tables are empty when the Database is first created, it shouldn't be necessary to add the Database from the /assets-folder.

Instead, you can use a SQLiteOpenHelper, which offers an onCreate()-method that can do the initial table-creation (an add some example data if necessary).

If you then update your app, you simply increase the Database-version and the onUpgrade()-method is called, where you can then perform the Database update.

See this other question: Run some code when user update my app

If your app comes with a huge Database and inserting entry's in the SQLiteOpenHelper isn't the right way to go, you can still check if the Database already exists and then do the updating (through the onUpgrade()-method) and keep the users data.

0

精彩评论

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

关注公众号