views:

59

answers:

1

Suppose an application stores some user related or users favorite records in its local database. When I upgrade my application, what happens to the db? As an developer, how do I prevent loss of data?

+1  A: 

You can see how to do this in the developer docs at http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

If your database schema does not change then you'll be fine as the data is kept during an upgrade. If you change your database schema you should use onUpgrade to bring a previous version of the database up to the latest version.

Al Sutton
Thanks for your answer ,but can i store the important records in an file so that even when i change the database scheme i can prevent data loss ,what will happen to prevailing files and preference when i upgrade.
ganesh
You can store the file on the SD card which will get ignored even on an uninstall. Files and preferences local to the app will also be preserved upon an upgrade.
Al Sutton