Krishnakant Dalal
Krishnakant Dalal

Reputation: 3578

Update application SQLite database created by Assets DB

I have Database in my application which is created by just coping the SQLite database file from the assets folder but now in the next release I want to update the database without losing the previous data.

Is there any Logic or way to copy the previous data and create a new database through SQLiteOpenHelper so that in near future I will not face this problem.

Thanks

Upvotes: 0

Views: 329

Answers (2)

kdehairy
kdehairy

Reputation: 2730

  1. Use this gist
  2. In the OnUpgrade method, copy your previous data from the old database.
  3. In the doUpgrade method, use your copied data to update the new database.

Upvotes: 1

Bolton
Bolton

Reputation: 2256

Previous data will be kept by default when users update to a new version. but you must keep in mind there will be new users never get a former version app. So you should add complete database in the assets folder.

Upvotes: 0

Related Questions