0
Hello. I am developing an application where it is necessary to synchronize the data at certain times. I am using Retrofit to connect to the api and send/receive the data, but each request needs to be made only when the previous request ends. How is it possible to do this?
Interface with the requests:
public interface DownloadService {
@GET("ciclo/current")
Call<JsonObject> getCicloAtual(@Header("Authorization") String token);
@GET("ciclo/last")
Call<JsonObject> getCicloLast(@Header("Authorization") String token);
@GET("imoveis")
Call<JsonObject> getImoveis(@Header("Authorization") String token);
@GET("pessoas")
Call<JsonObject> getPessoas(@Header("Authorization") String token);}
The client:
public class RetrofitClient {
private static String BASE_URL = "http://xxx.xxx.x.x:8000/api/";
private static Retrofit retrofit;
public static Retrofit getInstance(){
if(retrofit == null) {
return retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
public static AuthService authService() {return getInstance().create(AuthService.class);}
public static DownloadService downloadService() {return getInstance().create(DownloadService.class);}
public static SyncService syncService(){
return getInstance().create(SyncService.class);
}}
The next request must be made in the method where you receive the result of the previous request.
– ramaral
Is there any other way? There are still many requests to be made beyond these 4 code and I didn’t want it to get messy.
– Talita Ramos