1

I tried the code below, but it didn't work.

This code should check the contents of the EditText, and when the password is the same as the value of the string realpass, it should start secactivity Activity.

public void passthrought() {
    EditText passview = (EditText)findViewById(R.id.editText);
    String compare = passview.getText().toString();
    String realpass = "3402";
    if (compare == realpass) {
            Intent intent = new Intent(this, secactivity.class);
            startActivity(intent);
    } else passthrought();
}

Thanks in advance

Alexander Zhak
  • 9,140
  • 4
  • 46
  • 72

1 Answers1

0

Two problems:

  1. do not compare strings with ==, use .equals() for that
  2. yes, you end up in an endless loop the way you do it. You only want to check the password when the text in the EditText has changed. You can use a TextWatcher for that. See here for an example.
Community
  • 1
  • 1
SimonSays
  • 10,867
  • 7
  • 44
  • 59