Tiz*_*ica 2 php cookies android session-cookies
我正在开发需要通过服务器保存登录会话的应用程序..
首先尝试我要求用户进行身份验证,查找用户名/密码是否正确并保存Cookie以继续通过我的会话下载文件..
所以我暂时没有任何问题,但现在我想知道,如果我不想再次要求用户输入用户名/密码组合,最好的办法是:
保存Cookie然后恢复
或
保存用户名/密码和每次用户打开应用程序创建一个httpget到服务器并重新创建我的会话?
谢谢
编辑
我只是想知道哪个是最好的..保存Cookie或保存用户名/密码?
您可以使用SharedPreference类.成功登录后,它将用户凭据存储SharedPreference如下,
在SharedPreference中存储值
SharedPreferences sPrefs = getSharedPreferences("loginData", 0);
SharedPreferences.Editor editor = sPrefs.edit();
editor.putString("userName", "value");
editor.putString("password", "value");
editor.commit();
Run Code Online (Sandbox Code Playgroud)
要从SharedPreference中检索值,
SharedPreferences sPrefs = getSharedPreferences("loginData", 0);
String userName = sPrefs.getString("userName", "default value");
String password = sPrefs.getString("password", "default value");
Run Code Online (Sandbox Code Playgroud)