我需要调用多个Web服务,但每个步骤都使用了前一步骤的值,所以现在我有一个巨大的AsyncTasks链:每个AsyncTask在前一步骤的AsyncTask的onPostExecute()中执行。这非常丑陋,而且很难修改。我该如何避免这种情况?我想将每个步骤放在单独的函数中:
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
}
如何调用GetValueFromService()函数,以便step5()函数返回在GetValueFromService()函数中计算的值?