共享首选项在OREO中被删除

时间:2018-06-02 13:50:46

标签: android android-studio sharedpreferences android-sharedpreferences

我在登录时保存首选项并正确保存。从android studio再次运行应用程序后清除app sharedpreferences。 请找到以下代码:

public static String getStringValue(Context context, String key) {
        if (null != context && null != key) {
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
            return sharedPref.getString(key, (String)null);
        } else {
            return null;
        }
    }

    public static void putStringValue(Context context, String key, String value) {
        if (null != context && null != key) {
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
            Editor editor = sharedPref.edit();
            editor.putString(key, value);
            editor.apply();
        }

    }

0 个答案:

没有答案
相关问题