I'm new to android, my question is silly, my toast was just to appear when the user entered the wrong password or email, but it appears even when it's correct, what's wrong with my code?
try {
JSONObject json = new JSONObject(result);
System.out.println(json.getString("resource"));
JSONArray array = new JSONArray(json.getString("resource"));
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObj = array.getJSONObject(i);
System.out.println("Email : " + jsonObj.getString("tx_email"));
System.out.println("Password : " + jsonObj.getString("password"));
String email = jsonObj.getString("tx_email");
String password = jsonObj.getString("password");
if (mEmail.equals(email) && mPassword.equals(password)) {
Intent intent = new Intent(LoginActivity.this, MainActivity2.class);
intent.putExtra("result", result);
startActivity(intent);
}
else {
final Toast toast = Toast.makeText(getApplicationContext(), "Email ou Senha invalido(s)", Toast.LENGTH_SHORT);
toast.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
toast.cancel();
}
}, 250);
}
}
} catch (JSONException e) {
e.printStackTrace();
}}}}