我在登录活动中有一个“保存”复选框。如果用户检查它,下次,当应用程序启动时,跳过登录活动。虽然,如果用户想要注销,登录活动中的复选框将设置为未选中。这个问题,我无法解决。
登录活动保存部分:
saveLogin = loginPreferences.getBoolean("saveLogin", false);
if (saveLogin == true) {
etEmail.setText(loginPreferences.getString("email", ""));
etPassword.setText(loginPreferences.getString("password", ""));
saveLoginCheckBox.setChecked(true);
// editor.putBoolean("checked", true);
/* editor.putString("email", "etEmail"); // Storing string
editor.putString("password", "etPassword"); // Storing string*/
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(etEmail.getWindowToken(), 0);
String email = etEmail.getText().toString();
String password = etPassword.getText().toString();
if (saveLoginCheckBox.isChecked()) {
loginPrefsEditor.putBoolean("saveLogin", true);
loginPrefsEditor.putString("email", email);
loginPrefsEditor.putString("password", password);
loginPrefsEditor.commit();
} else {
loginPrefsEditor.clear();
loginPrefsEditor.commit();
}
Backendless.UserService.login(email, password, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
Toast.makeText(getApplicationContext(),"Sikeres bejelentlezés",Toast.LENGTH_SHORT).show();
Intent loginIntent = new Intent(LoginActivity.this, CategoryActivity.class);
LoginActivity.this.startActivity(loginIntent);
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(getApplicationContext(),"Sikertelen bejelentlezés",Toast.LENGTH_SHORT).show();
}
});
}
用户活动......这部分是注销按钮:
bLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Backendless.UserService.logout(new AsyncCallback<Void>() {
@Override
public void handleResponse(Void response) {
finish();
Intent logoutIntent = new Intent(UserAreaActivity.this, LoginActivity.class);
UserAreaActivity.this.startActivity(logoutIntent);
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(getApplicationContext(),"Nem sikerült kijelentkezni!",Toast.LENGTH_SHORT).show();
}
});
}
});
答案 0 :(得分:1)
您可以通过共享偏好设置来实现..如果用户登录后只是将值存储在共享偏好设置中,请说
Sp.putString("userinfo","loggedin");
Sp.commit();
每当你回来时,只要检查首选项是否已登录,然后jus转到主活动。显示登录活动
String data =SpEditor.getString("userinfo", null);
If(data!= null){
goto main}
Else goto login
Hopeit帮助!!