4

I want to get data from 3 different rest calls in a single activity. How can I do this using asynctasks. How can I co-ordinate 3 tasks?

Update: What I want to do is to wait for all the three tasks to complete before updating UI.

sab
  • 9,767
  • 13
  • 44
  • 51
  • Although you indicate that three calls must be made, you should clarify what you mean by co-ordinate the tasks. – Code Droid Jul 24 '12 at 01:11
  • Do you need to issue one task, get back a response then issue the next one. Or fire and forget until they are all returned. – Code Droid Jul 24 '12 at 01:11
  • 1
    CO-ORDINATE is too broad a term to use. It is ambiguous and hence I have docked a point. Chose your words carefully, and be specific. You need to define the constraints in your questions. – Code Droid Jul 24 '12 at 01:12
  • 1
    Once you have done this we will render our opinions on the best options if they have not already been rendered. – Code Droid Jul 24 '12 at 01:14
  • The best way of handling multiple AsyncTask is to call the next AsyncTask in side the onPost() method in first AsyncTask. The reason is while you are running a background thread using AsyncTask there is a UI thread also running. So too much of load will cause to exceed the heap size which is bad. – AnujAroshA Jul 24 '12 at 05:23
  • This question may be a duplicate but not a duplicate of http://stackoverflow.com/questions/4068984/running-multiple-asynctasks-at-the-same-time-not-possible See the "Update" in the question. – Jared Rummler Feb 29 '16 at 00:35

1 Answers1

1

You can refer to this post

Running multiple AsyncTasks at the same time — not possible?

AsyncTask uses a thread pool pattern for running the stuff from doInBackground(). The issue is initially (in early Android OS versions) the pool size was just 1, meaning no parallel computations for a bunch of AsyncTasks. But later they fixed that and now the size is 5, so at most 5 AsyncTasks can run simultaneously. Unfortunately I don't remember in what version exactly they changed that.

Community
  • 1
  • 1
Nirali
  • 13,571
  • 6
  • 40
  • 53