如何在asynctask背景中調用兩個不同的網絡url並分別調用onPostExecute
?任何想法請幫助我。以下是我的代碼,適用於一個網絡連接。在我的應用程序中有兩個不同的網絡連接。如何在asynctask中調用兩個不同的http連接
public class TheTask extends AsyncTask<Void, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... arg0) {
try {
String query = URLEncoder.encode("American%20Cheese%20Burger", "utf-8");
String url = "http://198.57.208.46.xyz";
Log.i("url",""+url);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
HttpEntity resEntity = response.getEntity();
_response=EntityUtils.toString(resEntity);
} catch(Exception e)
{
e.printStackTrace();
}
return _response;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
tv.setText(result);
}
}
我有兩個不同的URL我如何在postexecute從背景接受? – user2844177