This is my first login with android. The IF Condition is not working properly. When i give the correct password and username it exec the else part.Need help in this.
I can't see any errors in the code since i'm new to android studio. I used Latest android version (Pie) and Lolipop to test. same error happens.
public class MainActivity extends AppCompatActivity {
private EditText Name;
private EditText Password;
private TextView info;
private Button login;
private int counter = 5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Name = (EditText)findViewById(R.id.etName);
Password = (EditText)findViewById(R.id.etPassword);
info = (TextView)findViewById(R.id.tvInfo);
login = (Button)findViewById(R.id.btnLogin);
info.setText("No of Attempts remaining : 5");
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
validate(Name.getText().toString(), Password.getText().toString());
}
});
}
private void validate (String username, String userPassword){
if ((username == "Admin") && (userPassword == "admin")){
Intent Intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(Intent);
}
else
{
counter --;
info.setText("No of Attempts remaining :" + String.valueOf(counter));
if (counter == 0)
{
login.setEnabled(false);
}
}
}
}
I expect when the correct login info is given the app should go to SecondActivity.class .But actually it's not proceeding to SecondActivity with the correct details too.