Android - 让用户登录 [英] Android - Keep user logged in

查看:178
本文介绍了Android - 让用户登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP和MySQLi for Android进行登录。
我不明白的是如何让用户登录?我看到一个简单的教程,其中有人使用SQLite来获取安全信息,但我不知道这是否真的是安全的。
我应该如何保存用户信息以保持用户登录?

I'm trying to make a login with PHP and MySQLi for Android. What I don't understand is how to keep the user logged in? I saw a simple tutorial where someone used SQLite to safe information but I'm not aware if that is really secure way. How should I save the user information to keep the users logged in?

谢谢。

推荐答案

使用 SharedPreferences 在安卓

当您的登录使用

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
Editor editor = pref.edit();
//on the login store the login
editor.putLong("key_name", "long value"); 
editor.commit();

检索密钥的数据

pref.getString("key_name", "");
                            ^
   default value if the user is not loggedin

清除数据时注销

editor.remove("name");
editor.commit();

请参阅

Refer this Link for More

这篇关于Android - 让用户登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆