Android Sharepreferrence 保存数据到手机内存
package cn.jinyejun.android_logindemo.service; import java.util.Map; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.util.Log; public class LoginService { private final static String TAG = "LoginService"; /** * 保存数据到/data/data/cn.jinyejun.android_logindemo/sharePre目录下以info.xml格式保存 * * @param context * 上下文 * @param isAutoLogin * 是否自动登陆 * @param userName * 用户名 * @param password * 密码 */ public static void saveUserInfo(Context context, boolean isAutoLogin, String userName, String password) { SharedPreferences sp = context.getSharedPreferences("info", Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.putBoolean("isAutoLogin", isAutoLogin); editor.putString("userName", userName); editor.putString("password", password); editor.commit(); } /** * 读取/data/data/cn.jinyejun.android_logindemo/sharePre目录下的info.xml配置文件 * * @param context * 上下文 * @return userinfo 用户信息集合 */ public static Map<String, ?> getUserInfo(Context context) { SharedPreferences sp = context.getSharedPreferences("info", Context.MODE_PRIVATE); Map<String, ?> userinfo = sp.getAll(); Log.i(TAG, "userinfo= " + userinfo.isEmpty()); return userinfo; } }
相关推荐
yangkang 2020-11-09
lbyd0 2020-11-17
sushuanglei 2020-11-12
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gaobudong 2020-11-04
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30