0
I am developing a commercial APP, in this need to load all customers of the establishment, so I make a request requesting each client, because I need to send the Id of this in the URL of the request, until there is well, the problem is that when I do for example, 150 client request works, this results in 150 new AsyncTask().execute();
.
In a next scenario I need to order 700 customers, ie 700 new AsyncTask().execute()
then I need to wipe from memory those that have already been completed, already tried new AsyncTask().executeOnExecutor(Executors.newSingleThreadExecutor());
and I was unsuccessful.
I have a ArrayList<Integer>
that contains the ID of the clients that I need to 'pick up' (I have an Endpoint that returns the Client Ids that I can 'pick up'), so at each synchronization I send the 0 position of this array as parameter, then go the customer ID at the end remove the 0 position and make a check if there is still client without synchronizing.
Code of OnPostExecute()
:
clientesAguardandoSincronizar.remove(0);
mAsyncCliente = null;
if(clientesAguardandoSincronizar.size()>0){
//Executa novamente o Async de Clientes para trazer um a um.
mAsyncCliente = new AsyncCliente(context).execute();
}else{
//Executa proxima AsyncTask.
}
Honestly, I think the biggest problem is with your API. Why not have an endpoint in the API that allows you to get all users at once? That way, you would always make a single request in a single
AsyncTask
.– regmoraes
@regmoraes I don’t know if this is the case, but not always the developer has control over the Apis he needs to consume.
– Leonardo Lima
How’s your code? How are these tasks created? Sharing the code you’ve already done makes it easy for others to understand your problem and help you.
– Leonardo Lima
On the first comment, the API is from another company that I need to integrate our app with this other guy’s business system. I have no control over it, even requested such correction and did not.
– Erivaldo Dantas