I am using retrofit2 and recognized that sometimes the callback for Call.enqueue is not called.
Retrofit retrofit = new Retrofit.Builder().baseUrl(usuarioService.BASE_URL).addConverterFactory(GsonConverterFactory.create(usuarioService.g)).build();
usuarioService service = retrofit.create(usuarioService.class);
Call<String> user = service.verificarUsuario(login.getText().toString(), senha.getText().toString());
user.enqueue(new retrofit2.Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
String resultado = response.body();
if (resultado.equals("false")) {
Toast toast = Toast.makeText(MainActivity.this, "Senha ou usuário não existente", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
} else {
if (resultado.equals("true")) {
Toast toast = Toast.makeText(MainActivity.this, "ACESSO PERMITIDO", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
Intent intent = new Intent(MainActivity.this, MenuDrawer.class);
intent.putExtra("chave1", login.getText().toString());
startActivity(intent);
finish();
}
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
}
});
Suddenly that problem start to happen, does anybody knows how to fix it? These issue do not happen until some moments ago, I do not know what happened.
These happened just when i'm using mobile data, but when i'm used WIFI these never happened yet.
You have empty onFailure implementation so callback may be called but nothing happens. Try to log some information in onFailure method.
@Override
public void onFailure(Call<String> call, Throwable t) {
Log.w("MyTag", "requestFailed", t);
}
And you'll see if request failed and why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With