-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...c/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903235/Net1414080903235Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String,String> getUserInfo(Context context){ | ||
SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE); | ||
String number=sp.getString("number",null); | ||
String password=sp.getString("password",null); | ||
Map<String,String> userMap=new HashMap<>();//这里可以通过number找到对应的password | ||
userMap.put("number",number); | ||
userMap.put("password",password); | ||
return userMap; | ||
} | ||
} |