import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
/**
* Created by Administrator on 2018/11/26 0026.
*/
public class SharedPrefeerenceUtil {
private static String NAME = "SharedPrefeerence_name";
@SuppressLint("ApplySharedPref")
public static void putString(Context context, String key, String value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
sharedPreferences.edit().putString(key, value).commit();
}
public static String getString(Context context, String key) {
SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(key, "未获取到值");
}
@SuppressLint("ApplySharedPref")
public static void putInt(Context context, String key, int value)
基础封装SharedPreferences
最新推荐文章于 2024-07-31 17:40:34 发布
本文介绍了Android开发中常用的持久化存储方式SharedPreferences,详细讲解了其基本使用方法,并提供了一个实用的SharedPreferences封装工具类,帮助开发者更高效地进行数据保存和读取。
摘要由CSDN通过智能技术生成