问题
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";
}
回答1:
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 ?
来源:https://stackoverflow.com/questions/41843580/error-while-accessing-shared-preferences-of-android-apps-first-run