Error closing Progressidialog

Asked

Viewed 131 times

1

 public UserRest login(Usuario usuario,  final Context context){
    try {
        showProgress(context, "Aguarde", "Validando usuário...");

        UserService service =  ServiceGenerator.createService(UserService.class);
        Call<UserRest> call = service.login(usuario.getEmail(),usuario.getSenha());
        call.enqueue(new Callback<UserRest>() {

            @Override
           public void onResponse(Call<UserRest> call, Response<UserRest> response) {
               closeProgress();
               okhttp3.Response raw = response.raw();
               userRest = response.body();
               UsuarioDAO usuarioDAO = new UsuarioDAO(context);
               Usuario usuario = usuarioDAO.getUsuario();


               if (usuario != null  && userRest.getId()!=null) {
                   usuario.setFlagLogado("S");
                   usuarioDAO.controleLogin(usuario);
                   context.startActivity(new Intent(context, MenuActivity.class));
               }else {
                   new Handler().postDelayed(new Runnable() {
                       @Override
                       public void run() {
                           Toast.makeText(context, "Usuário não encontrado", Toast.LENGTH_SHORT).show();

                       }
                   }, 500);


               }

           }

           @Override
           public void onFailure(Call<UserRest> call, Throwable t) {
               closeProgress();
               Log.e(ConstantsTrocaae.TAG_LOG, t.getMessage());
               Toast.makeText(context, "Usuário não encontrado", Toast.LENGTH_SHORT).show();
           }
       });


    } catch (Exception e) {
        Log.e(ConstantsTrocaae.TAG_LOG, e.getMessage());

    }finally {
        closeProgress();
    }
    return userRest;

}

Would you like to know why I don’t add my file when I don’t find the user? The weirdest thing about finding it is.

private void showProgress(Context context, String titulo, String mensagem){
    progressDialog = new ProgressDialog(context);
    progressDialog.show(context, titulo, mensagem);
    progressDialog.setCancelable(true);

}

private void closeProgress(){
    if(progressDialog!=null && progressDialog.isShowing()){
        progressDialog.dismiss();
        progressDialog = null;
    }
}

2 answers

0

I noticed that in this case only closes when calling a new Intent and calling another Actvity, I told this way, in my case I have Activity that calls the login method in another class:

@OnClick(R.id.entrar)
public void login(View v) {

    final Usuario usuario = new LoginHelper(this).pegaUsuarioFormulario();

    try {

        if(validaUsuario(email,senha)){
            new UsuarioRetrofit().login(usuario,MainActivity.this);
        }

    } catch (Exception e) {
        Log.e(ConstantsTrocaae.TAG_LOG, e.getMessage());
    }
}

0

Fala Fabio,

No error in logCat?

I imagine the problem lies in that part:

finally {
   closeProgress();
}

Try to remove that part, it might solve.

Hugs.

Browser other questions tagged

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