Toast with problem

0

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();
        }}}}
    
asked by anonymous 30.05.2017 / 22:22

1 answer

0

All your else could be replaced by:

Toast.makeText(getApplicationContext(), "Email ou Senha invalido(s)", Toast.LENGTH_SHORT).toast.show();

You're putting it to show after a while, but the best way for you to do this would be via AsyncTask , take a look at the documentation so you can make this request in a better way.

    
31.05.2017 / 13:10