package com.hdl.photovoltaic.utils;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
|
|
public class SharedPreUtils {
|
|
|
/**
|
* 用户数据的存储
|
*
|
* @param key 键名
|
* @param value 键值
|
* @param context 上下文
|
* @return -
|
*/
|
public static boolean saveMyDataInfo(String key, String value, Context context) {
|
// 获取SharedPreferences对象,同时指定文件名称和访问权限
|
SharedPreferences sp = context.getSharedPreferences("MyData", Context.MODE_PRIVATE);
|
// 获取获取SharedPreferences的编辑器对象
|
SharedPreferences.Editor edit = sp.edit();
|
// 通过编辑器进行数据的存储
|
edit.putString(key, value);
|
edit.apply();
|
return true;
|
}
|
|
/**
|
* 读取用户数据
|
*
|
* @param key 键名
|
* @param context 上下文
|
* @return -value
|
*/
|
public static String getSharedPreferencesKey(String key, Context context) {
|
// 获取SharedPreferences对象,同时指定文件名称和访问权限
|
SharedPreferences sp = context.getSharedPreferences("MyData", Context.MODE_PRIVATE);
|
return sp.getString(key, "");
|
}
|
}
|