0

i am currently working on a project with retrofit, i have multiple WS calls and in order to use them i use the following code:

      call.enqueue(new Callback<Object>() {
                @Override
                public void onResponse(...

In some views i have multiple calls up to 5 or 6 and this was working fine , but when i advanced i nnoticed that i need to make the calls simultaneous so they can go one after the other .

Is there a way to make retrofit calls synchronized so they can go one after the other ?

Kingofkech
  • 129
  • 9

3 Answers3

1

You can make it synchronious by NOT adding a callback method.

For example:

service.getTasks().execute();
Zun
  • 1,553
  • 3
  • 15
  • 26
  • can you detail your answer ? i am farahead in my project (8 months of coding ) so replacing all the calls is not that simple, when and where execute the `service.getTasks().execute(); ` – Kingofkech Jun 28 '18 at 09:09
1

For synchronous requests with retrofit :

Call<List<Task>> call = retrofitService.getData(); 
List<Data>> data = call.execute().body();

You need to do this in the background thread though.

Udit
  • 1,037
  • 6
  • 11
1

Apparently, It seems you need chaining of you API calls to a single task rather than repetitive calling. Here, you can find something

RxJava

Chaining of API Calls

Hope it helps

Community
  • 1
  • 1
Anu Bhalla
  • 422
  • 4
  • 11