标签:
1、sharedPreference保存数据
1 package com.example.login.service; 2 3 import java.io.BufferedReader; 4 import java.io.File; 5 import java.io.FileInputStream; 6 import java.io.FileNotFoundException; 7 import java.io.FileOutputStream; 8 import java.io.InputStreamReader; 9 import java.util.HashMap; 10 import java.util.Map; 11 12 import android.content.Context; 13 import android.content.SharedPreferences; 14 import android.content.SharedPreferences.Editor; 15 16 public class LoginService { 17 public static void savaUserInfo(Context context, String username, String password) 18 { 19 SharedPreferences sp = context.getSharedPreferences("config", context.MODE_PRIVATE); 20 //获得一个sp编辑器 21 Editor editor = sp.edit(); 22 editor.putString("username", username); 23 editor.putString("password", password); 24 //相当于事务的提交 25 editor.commit(); 26 } 27 28 29 }
2、sharedPreference读取数据
SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE); String username = sp.getString("username", ""); String password = sp.getString("password", "");
标签:
原文地址:http://www.cnblogs.com/zhongyinghe/p/5386525.html