I have an android studio project for a personal app that has a simple password affixed to it in order to authenticate that I'm the one using it. My code is as follows:
public class StartActivity extends AppCompatActivity {
FloatingActionButton authenticate;
EditText passwordInput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
authenticate = (FloatingActionButton) findViewById(R.id.authenticateCheck);
passwordInput = (EditText) findViewById(R.id.inputPass);
authenticate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(passwordInput.getText().toString() == "Magic") {
Intent i = new Intent(StartActivity.this, LilyMainInterface.class);
startActivity(i);
} else {
passwordInput.setText("");
}
}
});
}
}
I've imported all of the necessary classes, but none of it is working. I don't see any problems and when I remove the if statement, the code successfully opens the correct activity. Other than that, it keeps considering the passwords as not matching.
Edit: I changed the
==
to
.equals()
as was said in a comment. It worked, however the reason why I wasn't doing it before was because android studio gives me a message saying that:
String values are compared with '==', not 'equals()'.
Why does .equals() work, even though android studio expressly states otherwise?