-3

So I have an app in progress that will ask user for some input and then display that input on main activity. Thought about using shared preferences for saving data, but for example when the update for the app gets available on Google Play, that data will be erased if user updates the app.

What should I use to save it on internal storage or sd card like a little backup file that will be restored when the app is updated?

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
DaxHR
  • 683
  • 1
  • 11
  • 30
  • 2
    Shared preferences don't get deleted in normal scenario of update. http://stackoverflow.com/questions/3860823/are-shared-preferences-in-android-apps-deleted-when-a-user-updates-the-app and http://stackoverflow.com/questions/12637737/what-will-happen-to-the-sharedpreferences-on-update-an-android-app – Rohit5k2 Feb 29 '16 at 14:40

1 Answers1

1

Prefenrences are persisted in the app after updates, try doing this:

SharedPreferences spref = getSharedPreferences("your_prefs_name", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = spref.edit();
editor.putString("dkey", value); 
editor.commit();

and your data will be safely store in the cache data of your app, ofcourse f you clear the data stored, or delete the Cache in the App-Manager your info will be gone for good.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97