1、sharedPreference保存数据

 package com.example.login.service;

 import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map; import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; public class LoginService {
public static void savaUserInfo(Context context, String username, String password)
{
SharedPreferences sp = context.getSharedPreferences("config", context.MODE_PRIVATE);
//获得一个sp编辑器
Editor editor = sp.edit();
editor.putString("username", username);
editor.putString("password", password);
//相当于事务的提交
editor.commit();
} }

2、sharedPreference读取数据

SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
String username = sp.getString("username", "");
String password = sp.getString("password", "");

最新文章

  1. Win下,通过Jstack截取Java进程中的堆栈信息
  2. ng-template寄宿方式
  3. Codeforces 715A. Plus and Square Root[数学构造]
  4. HW—指定字符替换Java(replace)---动态和静态定义字符串数组;
  5. jquery 使用ajax调用c#后台方法
  6. 引用 移植Linux到s3c2410上
  7. android IllegalStateException
  8. NTT+多项式求逆+多项式开方(BZOJ3625)
  9. Android View框架总结(七)View事件分发机制
  10. [ExtJS5学习笔记]第六节 Extjs的类系统Class System命名规则及定义和调试
  11. Devstack: A copy of worked local.conf I'm sharing with you.
  12. 【Vue 2.x】指令的学习
  13. Linux文件权限命令及配置
  14. redis list 清空记录小技巧
  15. 前端:Jquery 处理同一Name的Radio组时,绑定checked属性异常的问题.(已解决)
  16. Could not process inbound connection: Client [/rostopic_18439_1555659423249] wants topic , ROS md5sums do not match
  17. 【瞎搞题】gym226123 L. For the Honest Election
  18. elk日志平台搭建小记
  19. asp.net4.0
  20. FortiGate密码恢复

热门文章

  1. Libev学习笔记1
  2. opencv中遇到的的一些错误
  3. 在 Linux RedHatEL6 环境下安装配置 JDK1.7 + Tomcat7.0 + MySQL5.6
  4. 【剑指Offer学习】【面试题36:数组中的逆序对】
  5. 修改SQL Server登录密码(使用SQL Server身份登录)
  6. 关于java项目导入,所碰到的版本问题
  7. jz2440不能成功地启动文件系统, Failed to execute /linuxrc.
  8. Error D8016 '/ZI' and '/Gy-' command-line options are incompatible
  9. Javah生成JNI头文件
  10. vs2010中iostream.h出错