S
S
Sarrius2016-06-28 16:46:36
Android
Sarrius, 2016-06-28 16:46:36

How to deal with a bunch of issynchronous requests in Retrofit 2?

I'm trying to implement synchronization of the database: - first I
load the elements of the first level, then as each element of the first level is loaded, I load the elements of the second and so queries can be launched ad infinitum. How to queue all this so that the application does not crash? I rummaged on the off site, even empty (or I don’t know how to search correctly) I also tried to look here - without results.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
one pavel, 2016-06-28
@onepavel

Don't use Retrofit in activity

Z
zavbak, 2016-06-29
@zavbak

Use ExecutorService

public class MyService extends Service {
 
  final String LOG_TAG = "myLogs";
  ExecutorService es;
 
  public void onCreate() {
    super.onCreate();
    Log.d(LOG_TAG, "MyService onCreate");
    es = Executors.newFixedThreadPool(2);
  }
 ...
}

Where 2 is the number of threads available.
Look at the example on Startandroid

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question