Android共享偏好演示

Android共享偏好演示,android,Android,创建具有以下名称的文件 如何使用 公共类AppPreferences { } 如何使用: 1) 获取数据: boolean islogin=AppPreferences.readBoolean(启动屏幕。这是AppPreferences.islogin,false) 2) 输入数据: AppPreferences.WriteBolean(LoginActivity.this,AppPreferences.ISLOGIN,true) 这应该行得通,你能解释一下问题是什么吗?问题是什么?这似乎是使用

创建具有以下名称的文件

如何使用

公共类AppPreferences

{

}

如何使用:

1) 获取数据: boolean islogin=AppPreferences.readBoolean(启动屏幕。这是AppPreferences.islogin,false)

2) 输入数据:
AppPreferences.WriteBolean(LoginActivity.this,AppPreferences.ISLOGIN,true)

这应该行得通,你能解释一下问题是什么吗?问题是什么?这似乎是使用的方式…如何发布我的文档如果您想添加一个javadoc,只需在方法声明之前键入/**并按enter键,然后自动生成javadoc,您可以在
public static final String PREF_NAME = "XYZ";

@SuppressWarnings("deprecation")
public static final int MODE = Context.MODE_PRIVATE;

 public static final String ISLOGIN = "islogin";

public static void writeBoolean(Context context, String key, boolean value)
{
    getEditor(context).putBoolean(key, value).commit();
}

public static boolean readBoolean(Context context, String key,
                                  boolean defValue) {
    return getPreferences(context).getBoolean(key, defValue);
}

public static void writeInteger(Context context, String key, int value) {
    getEditor(context).putInt(key, value).commit();

}

public static int readInteger(Context context, String key, int defValue) {
    return getPreferences(context).getInt(key, defValue);
}

public static void writeString(Context context, String key, String value) {
    getEditor(context).putString(key, value).commit();

}

public static String readString(Context context, String key, String defValue) {
    return getPreferences(context).getString(key, defValue);
}

public static void writeFloat(Context context, String key, float value) {
    getEditor(context).putFloat(key, value).commit();
}

public static float readFloat(Context context, String key, float defValue) {
    return getPreferences(context).getFloat(key, defValue);
}

public static void writeLong(Context context, String key, long value) {
    getEditor(context).putLong(key, value).commit();
}

public static long readLong(Context context, String key, long defValue) {
    return getPreferences(context).getLong(key, defValue);
}

public static SharedPreferences getPreferences(Context context) {
    return context.getSharedPreferences(PREF_NAME, MODE);
}

public static SharedPreferences.Editor getEditor(Context context) {
    return getPreferences(context).edit();
}