在我的应用我的共享pref的文件中的用户信息。当用户输入的登录页面的详细信息,我想它的信息是共享的pref的文件只用户登录,我该怎么办呢?
In my application I got user info in shared pref file. When user enter their details on the log in page, I want only users whose info is in shared pref file to log in. How can I do that?
您可以使用您的应用程序的共享preferences。在preFS可以随时随地使用你的这些设置键来访问的 preFS
You can use your apps shared preferences. The prefs can be accessed anytime using the key you set for these prefs.
static final String KEY_USERNAME = "username";
static final String KEY_PASSWORD = "password";
if (saveLogInDetail) { //save username and pw to prefs
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Editor ed = prefs.edit();
ed.putString(KEY_USERNAME, theUsername);
ed.putString(KEY_PASSWORD, thePW);
ed.commit();
}
要访问这些信息,或者检查有效的用户名和密码使用这样的:
To access the information or check the valid username and password use this:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String storedUsername = prefs.getString(KEY_USERNAME, "Default Value if not found");
String storedPassword = prefs.getString(KEY_PASSWORD, ""); //return nothing if no pass saved
上一篇:包含复选框,文本列表视图越来越复位上滚动视图、复选框、文本、列表
下一篇:android.os.NetworkOnMainThreadException在android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(St