From 37150f7c57fa44a50811b1490f2b00cc842b0971 Mon Sep 17 00:00:00 2001 From: Lee20170303 <1805407781@qq.com> Date: Wed, 26 Apr 2017 23:24:44 +0800 Subject: [PATCH] =?UTF-8?q?#35=20#146=20=E7=AC=AC=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Net1414080903235Utils.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903235/Net1414080903235Utils.java diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903235/Net1414080903235Utils.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903235/Net1414080903235Utils.java new file mode 100644 index 00000000..cb9a9503 --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903235/Net1414080903235Utils.java @@ -0,0 +1,31 @@ +package edu.hzuapps.androidlabs.homeworks.net1414080903235; + +import android.content.Context; +import android.content.SharedPreferences; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Administrator on 2017/4/14. + */ +//实现登录功能:登录时保存用户数据到data.xml文件里面去 +public class Net1414080903235Utils { + public static boolean saveUserInfo(Context context,String number,String password){ + SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE); + SharedPreferences.Editor edit=sp.edit(); + edit.putString("username",number); + edit.putString("pwd",password); + edit.commit(); + return true; + } + public static Map getUserInfo(Context context){ + SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE); + String number=sp.getString("number",null); + String password=sp.getString("password",null); + Map userMap=new HashMap<>();//这里可以通过number找到对应的password + userMap.put("number",number); + userMap.put("password",password); + return userMap; + } +}