My toast is being shown even when my else is not called; was to be shown only when the user entered a wrong password or email, but even when equals
works, toast appears:
protected void onPostExecute(final String result) {
super.onPostExecute(result);
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");
String nickteste = jsonObj.getString("tx_nickname");
String cellteste = jsonObj.getString("nu_cellphone");
String snome = jsonObj.getString("tx_name");
if (mEmail.equals(email) && mPassword.equals(password)) {
Intent intent = new Intent(LoginActivity.this, MainActivity2.class);
//startActivity(intent);
//Intent ii = new Intent(LoginActivity.this, ActivityAttCad.class);
intent.putExtra("mEmail", email);
intent.putExtra("mPassword", password);
intent.putExtra("mNick", nickteste);
intent.putExtra("mCellphone", cellteste);
intent.putExtra("mNome", snome);
startActivity(intent);
}
else {
final Toast toast = Toast.makeText(getApplicationContext(), "Email ou senha inválido(s)", Toast.LENGTH_SHORT);
toast.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
toast.cancel();
}
}, 500);
}
}
} catch (JSONException e) {
e.printStackTrace();
}}}}