Im making an asynchronous call, im able to send a request to the server and getting my desired JSON(using postman) but for some reason the OnResponse and OnFailure methods are not being executed.
private List
Retrofit retrofit = new Retrofit.Builder()
.baseUrl( "http://192.168.100.4:8092/portal/")
.client(client.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestService requestService = retrofit.create(RequestService.class);
Call<List<Advert>> customerCall= requestService.getAdverts(accountNumber);
System.out.println("++++++++++++++ request was made +++++++++++++++++++");
customerCall.enqueue(new Callback<List<Advert>>() {
@Override
public void onResponse(Call<List<Advert>> call, Response<List<Advert>> response) {
Log.d("onResponse", "" + response.message());
System.out.println("++++++++++++++ was here+++++++++++++++++++");
if (response.isSuccessful()) {
adverts.addAll(response.body());
} else {
Toast.makeText(getContext(), "" + response.message(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<List<Advert>> call, Throwable t) {
Log.d("onFailure", t.toString());
System.out.println("++++++++++++++ I Failed +++++++++++++++++++");
}
});
return adverts;
}
I finally got the cause, I had another method which was interfering with my request, everything works perfectly now.
Hi, I hope you don't mind me asking, how did you manage to solve it? I mean, how did you know another method was interfering with your request?
I'm facing the same problem (everything works fine until I try to implement a lazy loading function for my recyclerView), and I don't know where to start, or how to tell if its because of an interfering method!
Enqueue did not work, but it seemed that the enqueue did not work due to an error to the incomplete completion of the previous task(enqueue) in the other task before this task(enqueue) was loaded.
Most helpful comment
Hi, I hope you don't mind me asking, how did you manage to solve it? I mean, how did you know another method was interfering with your request?
I'm facing the same problem (everything works fine until I try to implement a lazy loading function for my recyclerView), and I don't know where to start, or how to tell if its because of an interfering method!