【发布时间】:2015-01-19 12:57:29
【问题描述】:
嗨,在我的应用中,我使用了两个主题。 当主题发生变化时,将重新创建活动。此时我无法恢复编辑文本值。
@Override
protected void onResume() {
SharedPreferences mSharedPreferences = getSharedPreferences(
Constants.PREFERENCE_FILENAME, Activity.MODE_PRIVATE);
edt_kilo.setText(mSharedPreferences.getString(Constants.KILO_VAL,""));
edt_pound.setText(mSharedPreferences.getString(Constants.POUND_VAL,""));
if ((edt_centimeter.getText().toString().length() > 0)
|| (edt_feet.getText().toString().length() > 0)
|| (edt_inches.getText().toString().length() > 0)) {
imagelayout.setVisibility(View.VISIBLE);
super.onResume();
}
}
@Override
protected void onPause() {
super.onPause();
SharedPreferences.Editor edit = mSharedPref.edit();
edit.putString(Constants.KILO_VAL, edt_kilo.getText().toString());
edit.putString(Constants.POUND_VAL,edt_pound.getText().toString());
edit.commit();
}
@Override
public void onBackPressed() {
this.finish();
}
上述代码的问题是即使在按下设备的“返回”按钮完成活动后,值仍然保留,这是我不想要的。
当我“清除”edittext 中的值以及按下设备的“返回”按钮时,当我再次访问时,相同的值仍然存在。
如何处理这种情况
【问题讨论】:
标签: android android-edittext sharedpreferences