0

Gostaria que meu codigo fizesse a comparacao do email tambem se nao existir,mas ele so faz a comparacao da senha , como fazer a comparacao dos dois juntos ?

   if (mEmail.equals(email)) {
                if (mPassword.equals(password)) {

                    Intent intent = new Intent(LoginActivity.this, MainActivityListBooks.class);
                    //startActivity(intent);

                    //Intent ii = new Intent(LoginActivity.this, ActivityAttCad.class);
                    intent.putExtra("mId", id1);
                    intent.putExtra("mEmail", email);
                    intent.putExtra("mPassword", password);
                    intent.putExtra("mNick", nickteste);
                    intent.putExtra("mCellphone", cellteste);
                    intent.putExtra("mNome", snome);
                    startActivity(intent);


                    SharedPreferences sharedPreferences = getSharedPreferences("shared_pref_key", Context.MODE_PRIVATE);
                    makeText(LoginActivity.this, "Object stored in SharedPreferences", Toast.LENGTH_LONG);
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString("id", id1);
                    editor.commit();

                }
                    else {


                        final 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);
                }
                break;
1
  • if (mEmail.equals(email) && mPassword.equals(password)) ?
    – Isac
    30/07/2017 às 13:50

1 Resposta 1

1

Seu código deveria estar assim para funcionar corretamente:

if (mEmail.equals(email) && (mPassword.equals(password)) {

  Intent intent = new Intent(LoginActivity.this, MainActivityListBooks.class);
  intent.putExtra("mId", id1);
  intent.putExtra("mEmail", email);
  intent.putExtra("mPassword", password);
  intent.putExtra("mNick", nickteste);
  intent.putExtra("mCellphone", cellteste);
  intent.putExtra("mNome", snome);
  startActivity(intent);  

  SharedPreferences sharedPreferences = getSharedPreferences(
    "shared_pref_key", Context.MODE_PRIVATE);
  makeText(LoginActivity.this, "Object stored in SharedPreferences", 
           Toast.LENGTH_LONG);
  SharedPreferences.Editor editor = sharedPreferences.edit();
  editor.putString("id", id1);
  editor.commit();

} else {


    final 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);
}
2
  • Acklay muito obrigado,funcionou corretamente,mas porque o meu Toast é mostrado mesmo se o email e a senha forem corretas?
    – Thiago
    31/07/2017 às 10:50
  • Não deveria. O toast deve estar dentro do else em relação a comparação de e-mail e senha.
    – viana
    31/07/2017 às 11:25

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .