gpt4 book ai didi

Android 共享首选项时间限制

转载 作者:太空宇宙 更新时间:2023-11-03 11:49:59 26 4
gpt4 key购买 nike

在我的 android 应用程序中,我使用共享首选项来记住一些输入,这样无论何时启动应用程序,用户都不需要每次都键入输入.. 现在我需要注销共享首选项,如果使用该应用程序的时间是超过 24 小时.. 就像在 gmail 中一样,我们的登录详细信息将被记住 24 小时之类的东西,然后它会自动注销......我需要为此做些什么改变.. 我在下面给出我的代码..

用于内存的 SharedPreference

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);

}

最佳答案

您可以做的是,使用以下方法将上次登录时间存储在 sharedprefence 中:-

editors.putLong("lastlogin", new Date().getTime());

当用户下次启动应用程序时,获取上次登录时间并检查其是否早于 24 小时,如果是则使用以下方式清除数据:-

Deleting shared preferences

关于Android 共享首选项时间限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22011850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com