i use shared preference for saving data but when i install same application then my shared prefere开发者_StackOverflownce data not delete it remains as it is so how to delete shared preference data when i install same application without uninstall the application means just over write on the same application.
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
Editor editor = settings.edit();
editor.putString("MY_NAME", UserId);
editor.putString("PASSWORD", password);
editor.commit();
setResult(RESULT_OK);
I tried below code to make this work change it to suit your needs
SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
if (!isFirstRun)
{
// Code on first run
SharedPreferences.Editor editor = wmbPreference.edit();
editor.clear();
editor.commit();
}
else
{
// DO something
SharedPreferences.Editor editor = wmbPreference.edit();
editor.putBoolean("FIRSTRUN", false);
editor.commit();
}
精彩评论