When I answer this question I do so with one question in mind: Why in another AsyncTask
?
I assume the following scenario: through an event (user or application) an export of your local data to a web service is executed. With this, some things can happen:
All records are exported correctly, but in this case you have items that can be updated and created
Some records were not processed correctly
No record was processed correctly
The first thing you should keep in mind is that this information (who failed, who was processed correctly) should be given by the web service, since it is the web application that knows first-hand the result of its internal processes.
For what, in my opinion; You have 2 options:
Process records one by one : this is not optimal at all, but it would solve your need to inform in real time , it is not optimal because for each record the web server should send you a response on the status of each item, which at the level of concurrency becomes a mess; because for connectivity issues no shipment is made in a fixed time frame and it will also depend on how you handle the processes that make the shipments.
Process by batch : For me it is better that you execute a single call to process in a AsynTask
, Thread
, Runnable
(as you like) and that internally the service web generate a summary that is what you will show the user; while in your mobile application you would show the usual message that heavy work is being done and that it will take time (depending on how many records are)
Keep in mind that making an HTTP call is expensive depending on the time it takes to connect if the connection channel is not optimal (responsible bandwidth), do not forget to take into account the capacity of your web server if it is that the number of mobile clients is considerably large, this may cause you to be unavailable from your main service.