单个AsyncTask中的Android多Web服务调用

时间:2012-10-09 12:13:23

标签: android android-asynctask

如何从单个Asynctask调用多个Web服务调用,在此先感谢。

1 个答案:

答案 0 :(得分:2)

他们是同步的吗?然后拨打第一个,第二个......

public class WSTask extends AsyncTask<Void,Void,AccountsOverview_LABean>{


    @Override
    public void onPreExecute(){
        // show progress dialog or something if you want.
    }  

    @Override
    protected ArrayList<Object> doInBackground(Void... params) {
        try{
            ArrayList<Object> a=new ArrayList<Object>();
            a.add(WebService1()); // WebService1 returns the data that you want
            a.add(WebService2()); // WebService1 returns the data that you want
            a.add(WebService2()); // WebService1 returns the data that you want

            return a
            d.cancel();
        }
        return null;
    }

    @Override
    protected void onPostExecute(ArrayList<Object> param){
        // stop loading icon or loading dialog...

        // Manage the content of the arrayList like you need.

    } 

} //WSTask