SharedPreferences儲存資料工具類

2021-08-14 21:59:55 字數 1866 閱讀 5250

import android.content.context;

import android.content.sharedpreferences;

import android.content.sharedpreferences.editor;

public class preferenceutils

return mpreferences;

} /**

* 獲得boolean型別的值,沒有時為false

* * @param context

* @param key

* @return

*/public static boolean getboolean(context context, string key)

/*** 獲得boolean型別的值

* * @param context

* @param key

* @param defvalue

* @return

*/public static boolean getboolean(context context, string key,

boolean defvalue)

/*** 儲存boolean型別的資料

* * @param context

* @param key

* @param value

*/public static void putboolean(context context, string key, boolean value)

/*** 獲得string型別的值,沒有時為null

* * @param context

* @param key

* @return

*/public static string getstring(context context, string key)

/*** 獲得string型別的值

* * @param context

* @param key

* @param defvalue

* @return

*/public static string getstring(context context, string key, string defvalue)

/*** 儲存string型別的資料

* * @param context

* @param key

* @param value

*/public static void putstring(context context, string key, string value)

/*** 獲得int型別的值,沒有時為-1

* * @param context

* @param key

* @return

*/public static int getint(context context, string key)

/*** 獲得int型別的值

* * @param context

* @param key

* @param defvalue

* @return

*/public static int getint(context context, string key, int defvalue)

/*** 儲存int型別的資料

* * @param context

* @param key

* @param value

*/public static void putint(context context, string key, int value)

}

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...