【发布时间】:2014-03-27 12:54:03
【问题描述】:
在我的 android 应用程序中,我使用共享首选项来记住一些输入,这样每当应用程序启动时,用户就不需要每次都键入输入。现在如果使用应用程序的时间是,我需要注销共享首选项超过 24 小时.. 就像在 gmail 中一样,我们的登录详细信息将被记住 24 小时或其他时间,之后它将自动注销......我需要为此做些什么改变......我在下面给出我的代码......
用于记忆的共享偏好
if (spl1.equals("English") )
{SharedPreferences setting = this.getSharedPreferences(PREFS_NAME,0);
SharedPreferences.Editor editors = setting.edit();
editors.putString("lo", "lo");
editors.putString("fn", firstName);
editors.putString("mn",middleName);
editors.putString("ln",lastName);
editors.putString("dt",dates);
editors.putString("mt",months);
editors.putString("yrs",years);
//Passing exp no, heart no, lifepath number
editors.putLong("name11", sum11);
editors.putLong("name12", sum12);
editors.putLong("name10", sum10);
editors.commit();
Intent t = new Intent(FullExplanationEntry.this, TabLayoutActivityh.class);
}
退出
*
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.button04) {
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.remove("lo");
editor.commit();
finish();
}
return super.onOptionsItemSelected(item);
}
【问题讨论】:
-
“现在如果使用应用程序的时间超过 24 小时,我需要注销 sharedpreference”,您的意思是要清除 sharedprefrences 中的值?
-
正好.. 24 小时后.. 自动.. 值需要清除
标签: android timeout sharedpreferences