SharedPreferences處理資料工具類

2021-07-24 15:50:46 字數 1811 閱讀 7948

/**

* created by wk on 2016/11/14.

* sp檔案的工具類

*/public

class

sputils

/*** 寫入string型別value

**@param key

*@param value

*/public

void

putstring(string key, string value)

/*** 讀取string

**@param key

*@return 預設返回null

*/public string getstring(string key)

/*** int型別value

**@param key

*@param value

*/public

void

putint(string key, int value)

/*** sp中讀取int

**@param key

*@return 不存在返回預設值-1

*/public

intgetint(string key)

/*** 寫入long型別

**@param key

*@param value

*/public

void

putlong(string key, long value)

/*** 讀取long

**@param key

*@return 不存在返回預設值-1

*/public

long

getlong(string key)

/*** 寫入float型別

**@param key 鍵

*@param value 值

*/public

void

putfloat(string key, float value)

/*** 讀取float

**@param key 鍵

*@return 存在返回對應值,不存在返回預設值-1

*/public

float

getfloat(string key)

/*** 寫入boolean型別

**@param key

*@param value

*/public

void

putboolean(string key, boolean value)

/*** 讀取boolean

**@param key

*@return 不存在返回預設值

*/public

boolean

getboolean(string key)

/*** 獲取所有鍵值對

**@return map集合物件

*/public mapgetall()

/*** sp中移除某一組資料

**@param key

*/public

void

remove(string key)

/*** 查詢是否存在木某一組資料

**@param key

*@return true: 存在 false: 不存在

*/public

boolean

contains(string key)

/*** 清除所有資料

*/public

void

clear()

}

SharedPreferences的工具類

我們平常儲存一些資料,都會用到sharedpreferences,他是儲存在手機裡面的,具體路徑是data data 你的包名 shared prefs 儲存的檔名.xml,sharedpreferences的使用也很簡單,我自己就寫了乙個sharedpreferences的工具類 package ...

SharedPreferences的工具類

import android.content.context import android.content.sharedpreferences import android.content.sharedpreferences.editor sharedpreferences的工具類 author w...

SharedPreferences的工具類

import android.content.context import android.content.sharedpreferences import android.content.sharedpreferences.editor sharedpreferences的工具類 author w...