SharedPreferences简单使用 String类型数据保存和获取 见笑见笑
来源:互联网 发布:淘宝卖家怎么看钱到账 编辑:程序博客网 时间:2024/06/05 08:19
package com.example.denglujiemian.zhaoi.Utils;
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferencesUtils {
private static final String path ="urse";
// 保存用户的密码
public static void setPasswd(Context context,String key,String Value) {
SharedPreferences sp = context.getSharedPreferences(path, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(key, Value);
editor.commit();
}
// 获取用户的密码
public static String getPasswd(Context context,String key) {
SharedPreferences sp = context.getSharedPreferences(path, Context.MODE_PRIVATE);
return sp.getString(key, null);
}
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferencesUtils {
private static final String path ="urse";
// 保存用户的密码
public static void setPasswd(Context context,String key,String Value) {
SharedPreferences sp = context.getSharedPreferences(path, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(key, Value);
editor.commit();
}
// 获取用户的密码
public static String getPasswd(Context context,String key) {
SharedPreferences sp = context.getSharedPreferences(path, Context.MODE_PRIVATE);
return sp.getString(key, null);
}
}
使用方式
// 把数据保存到SharedPreferences里边
SharedPreferencesUtils.setPasswd(getApplicationContext(),"mPhoneCode", mPhoneCode);
SharedPreferencesUtils.setPasswd(getApplicationContext(),"mPassword", mPassword);
//获取数据
String user_id = SharedPreferencesUtils.getPasswd(mContext,"user_id");
String user_name = SharedPreferencesUtils.getPasswd(mContext,"user_name");
String user_header_img = SharedPreferencesUtils.getPasswd(mContext,"user_header_img");
0 0
- SharedPreferences简单使用 String类型数据保存和获取 见笑见笑
- Android --使用SharedPreferences保存和获取数据
- Android SharedPreferences保存/获取简单本地数据
- 使用SharedPreferences保存复杂类型的数据
- VB6简单的记事本程序,高手见笑了!
- 顿悟QT,见笑
- 新手,请勿见笑
- 使用SharedPreferences保存和读取数据
- 使用SharedPreferences保存数据
- Android使用SharedPreferences保存HashSet<String>数据不能更新成功
- 使用SharedPreferences保存对象(图片)类型的数据
- Android数据存储之SharedPreferences的简单使用(保存用户名和密码)
- 庆祝万圣节,ps一下,见笑
- 在Android中使用SharedPreferences保存简单的数据
- 使用SharedPreferences来保存数据
- 使用SharedPreferences对象保存数据
- SharedPreferences类供开发人员保存和获取基本数据类型的键值对.该类主要用于基本类型, 例如boolean,float.int,long和string. SharedPr
- SharedPreferences保存各种类型的数据
- c++实验7,
- 找出数组中只出现一次的两个数字
- java 实现折半(二分)查找
- org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 105; cvc-elt.1: 找不到元素 'beans' 的声明。
- Matlab中cell与其它类型之间的转换
- SharedPreferences简单使用 String类型数据保存和获取 见笑见笑
- C++第七次实验——实验(项目1:数组素数排序)
- 取消屏幕旋转时的动画的方法
- java多线程的总结
- android 矢量图的打造
- Mybatis从0开始的例子
- python爬虫解决验证码的思路
- 基于stm32的超声波测距
- android关于点击事件的几种写法。