Android Retrofit 2 wait on multiple requests

Android Retrofit 2 wait on multiple requests

Date : October 17 2020, 01:08 AM
will be helpful for those in need 1 hacky way of doing it would be to keep 2 flag variables loadTroopsflag & loadTroopMarkersflag.Then in the onSuccess callbacks of each check whether both are true and if they are then both your requests are complete. There might be edge cases in implementing a workaround like this but it should generally work. In case your requests depend on each other then as you will need to use nested called ie,
code :
    repositoryService.loadTroops(new TroopCallback() {
        public void onSuccess(List<Troop> troops) {
            Log.d("RETROFIT", "SUCCESFULLY LOADED TROOPS SIZE: " + troops.size());

            repositoryService.loadTroopMarkers(new TroopMarkerCallback() {
            public List<TroopMarker> troopMarkers;

            public void onSuccess(List<TroopMarker> troopMarkers) {
                Log.d("RETROFIT", "SUCCESFULLY LOADED TROOPMARKERS SIZE: " + troopMarkers.size());
 //Should now here when I'm done with my requests.
    Log.d("RETROFIT", "DONE");

Share : facebook icon twitter icon
How to make multiple requests with reactive android and retrofit

How to make multiple requests with reactive android and retrofit

By : jonasjore
Date : March 29 2020, 07:55 AM
should help you out Just use Observable.range and concatMap your calls with it. If you don't know your upper range, you can use takeUntil with some condition.
Something like this:
code :
Observable.range(0, Integer.MAX_VALUE)
            .concatMap(pageNum -> api.getShops(pageNum).map(doYourMapping))
            .takeUntil(shops -> someCondition);
.flatMapIterable(shops -> shops)
Multiple requests using Retrofit and RXJava

Multiple requests using Retrofit and RXJava

By : Uchiha Clan
Date : March 29 2020, 07:55 AM
may help you . I have a service called verifyData. I need call this service N number of times. , If you want to make sequential calls, use .concatMap
code :
            .concatMap(s -> services.verifyData(Integer.parseInt(s)))
            .flatMap(s -> services.verifyData(Integer.parseInt(s))
                    .subscribeOn(Schedulers.io()), maxConcurrent)
Android:Retrofit: Multiple consecutive async requests. Тoo many nested items

Android:Retrofit: Multiple consecutive async requests. Тoo many nested items

By : dhruvil's Creation
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can either take time to learn Rx RXjava2
or you can split up your code like this
code :
RestClient restClient = RestClientFactory.getRestClient();
Call<List<Company>> companyList = restClient.getCompaniesList(filters);


private Callback<List<Company>> getCompanyListCallback() {
    return new Callback<List<Company>>() {
        public void onResponse(Call<List<Company>> call, Response<List<Company>> response) {
            if (response.isSuccessful()) {
                RestClient restClient = RestClientFactory.getRestClient();
                Call<List<Catalog>> catalogList = restClient.getCatalogsList(filters);

        public void onFailure(Call<List<Company>> call, Throwable throwable) {


private Callback<List<Catalog>> getCatalogsListCallback() {
  return   new Callback<List<Catalog>>() {
        public void onResponse(Call<List<Catalog>> call, Response<List<Catalog>> response) {
            if (response.isSuccessful()) {
                // HERE SOME NEED CODE!!!

        public void onFailure(Call<List<Catalog>> call, Throwable throwable) {

Multiple Http requests called and stored in one array, but how to wait until all requests finish before working with arr

Multiple Http requests called and stored in one array, but how to wait until all requests finish before working with arr

By : Helloada
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have a array of values I want to loop over. Each of these values will be used to make an http request to a server. From the server I will recieve a response for each request. I want to store all these responses in a single array and then do work on the array once ALL requests have finished. Due to the async nature of my code I am not sure how to make the application wait until all the requests have finished. What is happening is I am making the requests, but the work I want to do with the array is already starting before ALL the requests have finished due to the async nature. How can I make this code "synchronous" in the sence it waits until all requests have finished before starting to do the work with the listOfResponses array , Just map it to an array of promises:
code :
  const promises = list.map(word => new Promise(resolve => {
   var url = 'http://notsurehowtomakethisworksoiamaskingstackoverflow.com/api/words/' + word;
   request(url, {
     json: true
   }, (err, res) => {
     if (err) {
       return reject(err);
 Promise.all(promises).then(results => {
How to make multiple request and wait until data is come from all the requests in retrofit 2.0 - android

How to make multiple request and wait until data is come from all the requests in retrofit 2.0 - android

By : Izaiah
Date : March 29 2020, 07:55 AM
like below fixes the issue The clean and neat approach to wait until all your requests will be done is to use Retrofit2 in conjunction with RxJava2 and its zip function.
What zip does is basically constructs new observable that waits until all your retrofit Observable requests will be done and then it will emit its own result.
Related Posts Related Posts :
  • Null data on resumed activity
  • Google Drive REST API : file.getCreatedTime() returns always null
  • android Transform Exception
  • Correct way to check disk space available for Android app?
  • Round up float .25
  • Android - deleting characters on button press
  • Android - one date and two time pickers in one dialog
  • Change background of particular item to a colour and other items to different colour
  • How to use horizontal view pager inside recycler view
  • Fragment is null whenever trying to reload fragment after a delete
  • Add horizontal line inside EditText
  • How to ask and accept all permissions in only one confirm alert dialog in Android 6.0
  • How to handle configuration change in Snackbar?
  • Android Studio 2.2.2 LLDB 2.2 update issue
  • Gradle build showing error when trying to add MapsActivity
  • In Android Intent why we write ActivityTwo.class in second argument?
  • Android - Connected Tests Results Directory
  • prevent partial overlapping of shape drawable stroke
  • How to rapidly prototype an image recognition application using Machine learning & neural network?
  • Volley RetryPolicy querying twice before timeout time is reached
  • Use custom RenderScript in system signed application
  • Automatic reply for whatsapp messages approach
  • Auto active/deactive Location & Data
  • error: cannot find symbol class Crashlytics and Fabric
  • SurfaceView how to Re-Create if it has been destroyed
  • Espresso idlingResource - how to register?
  • Change encoding of androidManifest.xml to UTF-8 in Android Studio 3
  • MS Syncframework 4 - no response after 5 minutes of server side processing
  • Kotlin clear an adapter
  • Parsing datetime to UTC
  • How to turn off keyboard icon at TimePicker?
  • How to make Primary key Auto increment while using Composite Primary keys in Room persistent library?
  • Passing between Activities using Intents
  • JSONObject fields in GSON class - Remains empty
  • Include headers directories for gradle generation with JNI interaction
  • ListView updates the entry only when the application is restarted again
  • SyncFailed Error:Cause: org/jetbrains/plugins/gradle/tooling/ModelBuilderService
  • minSdkVersion cannot be smaller than version 14 declared in library support-v4:26.0.0-alpha1 Manifest Merger Failed
  • Bluetooth connect works on some devices
  • How add space (e.g.height = 20dp) between searchView and dropdown list?
  • in Android studio Register New File Type Association for ttf
  • phoneGap 3.5.0 to 6.5.0 and api status was undifined
  • CountDownTimer - how to start from another method rather than Oncreate method
  • url not showing in WebView inside a Dialog
  • adjusting height of StackLayout element
  • I can't able to take my Images to new activity that are loaded from SD card
  • Paging Library invalidating data source not working
  • build.gradle warning 'avoid using + in version numbers'
  • NumberFormatException when setting SimpleDateFormat
  • How to add more work for 1 hit of "take image" button for camera app?
  • TabHost activity is not working
  • Travis CI - Android Build Script
  • Anko's uiThread sporadically not fired
  • Structure Database Firestore Posts
  • Displaying a Matrix
  • Adding a library with the notation ext: 'aar' or @aar doesn't import the transitive dependencies
  • Play Console Crash Reports (OutOfMemory)
  • Updated Android app built with Codename One instead of Android Studio
  • USB Communication with DTR/DTE enabled
  • This field leaks a context object
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com