类 SharedPreferencesUtil


  • public class SharedPreferencesUtil
    extends java.lang.Object
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static boolean getBoolean​(android.content.Context context, java.lang.String key, boolean value)
      读取boolean标识从sharedPreferences中
      static int getInt​(android.content.Context context, java.lang.String key, int defValue)
      读取int标识从sharedPreferences中
      static long getLong​(android.content.Context context, java.lang.String key, long defValue)
      long标识从sharedPreferences中
      static java.lang.String getString​(android.content.Context context, java.lang.String key, java.lang.String defValue)
      读取String标识从sharedPreferences中
      static void putBoolean​(android.content.Context context, java.lang.String key, boolean value)
      写入Boolean变量至sharedPreferences中
      static void putInt​(android.content.Context context, java.lang.String key, int value)
      写入int变量至sharedPreferences中
      static void putLong​(android.content.Context context, java.lang.String key, long value)
      写入long变量至sharedPreferences中
      static void putString​(android.content.Context context, java.lang.String key, java.lang.String value)
      写入String变量至sharedPreferences中
      static void remove​(android.content.Context context, java.lang.String key)
      从sharedPreferences中移除指定节点
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • SDK_INIT_UPDATE_TIME

        public static final java.lang.String SDK_INIT_UPDATE_TIME
        另请参阅:
        常量字段值
      • SDK_INIT_UPDATE_INTERVAL

        public static final java.lang.String SDK_INIT_UPDATE_INTERVAL
        另请参阅:
        常量字段值
    • 构造器详细资料

      • SharedPreferencesUtil

        public SharedPreferencesUtil()
    • 方法详细资料

      • putBoolean

        public static void putBoolean​(android.content.Context context,
                                      java.lang.String key,
                                      boolean value)
        写入Boolean变量至sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        value - 存储节点的值
      • getBoolean

        public static boolean getBoolean​(android.content.Context context,
                                         java.lang.String key,
                                         boolean value)
        读取boolean标识从sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        value - 没有此节点的默认值
        返回:
        默认值或者此节点读取到的结果
      • putString

        public static void putString​(android.content.Context context,
                                     java.lang.String key,
                                     java.lang.String value)
        写入String变量至sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        value - 存储节点的值String
      • getString

        public static java.lang.String getString​(android.content.Context context,
                                                 java.lang.String key,
                                                 java.lang.String defValue)
        读取String标识从sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        defValue - 没有此节点的默认值
        返回:
        返回默认值或者此节点读取到的结果
      • putInt

        public static void putInt​(android.content.Context context,
                                  java.lang.String key,
                                  int value)
        写入int变量至sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        value - 存储节点的值int
      • getInt

        public static int getInt​(android.content.Context context,
                                 java.lang.String key,
                                 int defValue)
        读取int标识从sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        defValue - 没有此节点的默认值
        返回:
        返回默认值或者此节点读取到的结果
      • putLong

        public static void putLong​(android.content.Context context,
                                   java.lang.String key,
                                   long value)
        写入long变量至sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        value - 存储节点的值long
      • getLong

        public static long getLong​(android.content.Context context,
                                   java.lang.String key,
                                   long defValue)
        long标识从sharedPreferences中
        参数:
        context - 上下文环境
        key - 存储节点名称
        defValue - 没有此节点的默认值
        返回:
        返回默认值或者此节点读取到的结果
      • remove

        public static void remove​(android.content.Context context,
                                  java.lang.String key)
        从sharedPreferences中移除指定节点
        参数:
        context - 上下文环境
        key - 需要移除节点的名称