Error while accessing shared preferences of Android App's first run

六月ゝ 毕业季﹏ 提交于 2019-12-25 07:47:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!