kotlin sharedpreference工具类
上代码,没什么好说明的: 补充一点,声明工具类,class 需要更改为 object (类声明时) private const val FILE_NAME = "global_data" fun put (context: Context , key: String , objects: Any) { var sp = context.getSharedPreferences( FILE_NAME , Context. MODE_PRIVATE ) var editor = sp.edit() LogUtil.d( "put key $ key , value $ objects as String" ) when (objects) { is String -> { LogUtil.d( "put info begin -- " ) editor.putString(key , objects ) } is Int -> { editor.putInt(key , objects ) } is Boolean -> { editor.putBoolean(key , objects ) } is Float -> { editor.putFloat(key , objects ) } is Long -> { editor.putLong(key , objects ) } }