访问 Android 应用程序首次运行的共享首选项时出错 [英] Error while accessing shared preferences of Android App's first run
本文介绍了访问 Android 应用程序首次运行的共享首选项时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我在安装后第一次运行我的 Android 应用程序并访问共享首选项时,我都会收到此系统错误 -
Whenever I run my Android app for the first time after installation and access the shared preferences, I get this system error -
remove failed: ENOENT (No such file or directory) : /data/user/0/com.example.ap/shared_prefs/com.google.android.gms.appid.xml.bak
我无法弄清楚此错误的含义.任何帮助将不胜感激.谢谢
I am not able to figure out what this error means. Any help will be appreciated. Thanks
访问共享首选项的代码 -
Code to access shared preferences -
String setOrNot;
SharedPreferences sharedPref = getSharedPreferences("LastFetchTimeFile",MODE_PRIVATE);
if(sharedPref.contains("LastFetchTime"))
{
String lastFetchTime = sharedPref.getString("LastFetchTime", null);
setOrNot = lastFetchTime;
}
else
{
setOrNot = "notSetYet";
}
推荐答案
移除 if 条件,共享首选项会为您处理.我会做的是
Remove the if condition, shared preference handles that for you. What i would do is
String setOrNot;
SharedPreferences sharedPref = getSharedPreferences("LastFetchTimeFile",MODE_PRIVATE);
setOrNot = sharedPref.getString("LastFetchTime", "notSetYet");
你能告诉我哪个设备/操作系统吗?
Also can you tell me which device/os ?
这篇关于访问 Android 应用程序首次运行的共享首选项时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文