Can I get results from the Asyntask that run on another AsynTask?

1

The problem is the following: In the app that I develop, I reach a point where I have to export all the records stored locally to a webservice (which is already running), but I'm looking for a way to get the result of each asyntask executed in real time, the result is a counter of which records were updated, generated and which are those that could not do any of the previous two;

Any suggestions I would appreciate it

    
asked by Mark Dev 11.08.2016 в 17:59
source

3 answers

1

As I understand your problem. You only need to update the value of each one of your variables for the progressbar in each result of asynckTask and call a function that updates the progressbar according to the value of each variable.

    
answered by 12.08.2016 в 06:38
1

You can use the method publishProgress to send from doInBackground() information every time an action is executed and you can update the UI from the main thread by implementing the onProgressUpdate() method in either progressDialog or any component of the iterfaz you use to show the progress of the task.

    
answered by 12.08.2016 в 19:10
0

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.

        
    answered by 15.08.2016 в 21:29