F
F
fman22020-01-10 16:53:55
Android
fman2, 2020-01-10 16:53:55

How to make multiple HTTP requests in Android?

Friends, hello everyone.
Tell me how to do it right. I have a Dto class that is filled with data from several URLs, after which a callback is called and this Dto gets into it.
Something like:

service.request(new Callback() {
           public void success(User user) {
                 // ....
          }
    }
});

So in service.request, in order to correctly "collect" the User, I need to make 3 asynchronous HTTP requests. How to do it correctly using okhttp3 and not to fuss with callbacks and AsyncTask.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-01-11
@zagayevskiy

Use retrofit+rxjava, combine the results of three queries.
Or use kotlin and coroutines, make three requests, wait for them and construct the object.
Or block the builder and wait for the results of three requests in callbacks.
Asynctask is not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question