I have to make several calls to a web service, but each step uses the values from the previous step, so right now I have a huge chain of AsyncTasks: each AsyncTask is executed in the onPostExecute() of the AsyncTask of the previous step. This is very very ugly, and very hard to modify. How can I avoid this? I would like to put each step in a separate function:
int step5() //this function is on the main UI thread
{
return getStep5ValuesFromWebService() + valuesFromPreviousSteps;
}
int getStep5ValuesFromWebService()
{
//do work on new thread
//GetValueFromService(); <-- this is the function that returns an int from the web service, but it has to be called from another thread
}
How to call GetValueFromService() so that the step5() function returns the value calculated in the GetValueFromService() function?