jeudi 25 juin 2015

android - Basic security feature

I'm trying to do the most basic form of security at the start of my app, where if you put in the right name and surname, a new activity will be called.

See my code here:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button buttonIntroSubmit = (Button) findViewById(R.id.button_intro);

    Intent introPass = new Intent(this, questionareActivity.class);

    buttonIntroSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            EditText firstName = (EditText) findViewById(R.id.first_name);
            EditText lastName = (EditText) findViewById(R.id.last_name);
            TextView test = (TextView) findViewById(R.id.test);

            String fullName = firstName.getText() + " " + lastName.getText();
            String password = "Mieke Snyman";

            test.setText(fullName);

            if(fullName !== password) {
                String toastPass = "Approved";
                Toast pass = Toast.makeText(getApplicationContext(), toastPass, Toast.LENGTH_LONG);
                pass.show();
            }
        }
    });
}

If I type in exactly "Mieke" at the firstName field and exactly "Snyman" at the lastName, it shows "Mieke Snyman" at the test TextView which I assigned the text content via variable "fullName". But if I use that same variable for the if condition it doesn't go into the if.

Any ideas why? Maybe a white space character or something i'm missing in my if condition?

Aucun commentaire:

Enregistrer un commentaire