1
votes

I have an application that doesn't use databases but it has some shared preferences. During application update, I need to perform some changes to the existing preferences and also adding some new preferences.

By googling I found that, we can handle application upgrade migration through onUpgrade() method.But that method requires database name that doesn't exists in my app.

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

Please suggest me a solution to upgrade the existing shared preferences during application update.

3

3 Answers

3
votes

Store a version number in your shared preferences from now on that you can use to determine exactly which schema the existing shared preferences use, and from there do whatever is needed.

For the current situation, the lack of the "schema version" preference is your indicator that you need to do whatever it is you need to do.

(onUpgrade() won't help you in this situation.)

0
votes

I think you are mistaken.

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

this is a function of SQLiteOpenHelper class. Its called when you upgrade the database/increment the version no of your database.

0
votes

i think you can do like this

SharedPreferences mySharedPreferences=getSharedPreferences("name",mode);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putString(fileName, fileName);
editor.commit();