我正在尝试使用 PHP 和 MySQLi for Android 进行登录。
我不明白的是如何保持用户登录状态?我看到一个简单的教程,其中有人使用 SQLite 来保护信息,但我不知道这是否真的安全。
如何保存用户信息以保持用户登录状态?
谢谢。
Use the SharedPreferences http://developer.android.com/reference/android/content/SharedPreferences.html在安卓中
当您登录时使用存储数据
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();
参考这个Link http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/了解更多
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)