所以,这是我的 Android MainActivity,但特别是这段代码:
public void checkUser(View view) {
// Next Activity to move on to
Intent intentSuccess = new Intent(this, Home.class);
Intent intentFail = new Intent(this, LoginFailActivity.class);
EditText usernameText = (EditText) findViewById(R.id.user_field);
String username = usernameText.getText().toString();
EditText passwordText = (EditText) findViewById(R.id.pword_field);
String password = passwordText.getText().toString();
if (username == "admin" && password == "password") {
startActivity(intentSuccess);
} else {
startActivity(intentFail);
}
}
即使我输入“admin”和“password”,它每次都会进入 intentFail。我已经检查了一个测试活动,它正确地将字符串传递给它,没有问题。
请帮助我,并在此先感谢您!!