0
Man Toast is being shown even when my Else is not called; it was to be shown only when the user enters wrong password or email, but even when the equals works, the 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();
}}}}
Maybe it’s my fault but the if part (mEmail.equals(email) && mPassword.equals(password)) { ... shouldn’t be outside the loop for ?
– Wagner Soares
From what I understand, you are comparing various read data from a JSON file with email and password. Probably only one of these data corresponds to the condition in
if, thus, in the others, he falls into theelse– Artur Trapp
The code is correct. I suggest debugging to analyze better.
– Luiz Lanza