Reputation: 5166
Is there any way to delete or reset shared preferences data when re-installing an app, without uninstalling the app and installing it?
What I mean to say is, currently, I am developing an app which uses shared preferences, but as I am still developing it, I keep running and uploading the app to the test phone through Eclipse after I make changes. Currently I am unable to run the app from the very beginning of its expected process ( after the first time) , without uninstalling the older version and then uploading the app again.
Upvotes: 0
Views: 2981
Reputation: 35661
Check in your launch activity whether to clear the preferences or not with a function like this:
SharedPreferences prefs = this.getSharedPreferences("prefs", Context.MODE_PRIVATE);
if (!prefs.getBoolean("FirstRun", true)) {
// Not the first time so clear prefs
prefs.edit().clear().commit();
} else {
// Set the value for future runs
prefs.edit().putBoolean("FirstRun", false).commit();
}
Upvotes: 0
Reputation: 14590
For this in your launching activity onCreate() method check whether the shared preference file exist or not if it is exist delete it.and later create it where ever you want.. you can check the preference file exist or not like this..
public boolean isFirstTime() {
return getDatabasePath("your file name").exists();
}
Upvotes: 1
Reputation: 11194
Clear the activities like :
Intent intent = new Intent(this, Login.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Clear ur shared Pref :
SharedPreferences pref = this.getSharedPreferences("mypref", Context.MODE_PRIVATE);
getSharedPreferences("pref", Context.MODE_PRIVATE).edit().clear().commit();
Upvotes: 1