Toast with problem

Asked

Viewed 62 times

0

I’m new to android,my question is silly,my Oast was only to appear when the user type the wrong password or email,but it appears even when it is correct, what is 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();
        }}}}

1 answer

0

All yours else could be exchanged for:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.