【发布时间】:2016-10-12 04:24:38
【问题描述】:
所以我目前在 SharedPreferences 中的上下文中遇到问题,其中显示 LoginActivity.this。这是我的 device.java 类,而 LoginActivity 是我要从中调用此方法的 Activity。那么它会像 Device.This 还是类似的东西?
方法:
public void validateLogin(String username, String password, String ipAddress) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
if (sharedPreferences.contains("ip") && sharedPreferences.contains("username") && sharedPreferences.contains("password")) {
String strUsername = sharedPreferences.getString("username", username);
String strPassword = sharedPreferences.getString("password", password);
String strIpAddress = sharedPreferences.getString("ip", ipAddress);
//performLogin(strUsername, strPassword, strIpAddress);
}
}
public void saveSP(String username, String password, String ipAddress) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
sharedPreferences.edit()
.putString("ip", ipAddress)
.putString("username", username)
.putString("password", password)
.commit();
}
【问题讨论】:
标签: variables android-studio android-activity sharedpreferences mobile-application