我有一个异步任务,如果成功生成其他5个网络门户,则会记录用户。截至目前,它在一个异步任务(一次一个)中完成所有工作。如何让它们同时进行。
这是我的代码,用于了解我到目前为止所拥有的内容:
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpClientHandler.httpClient = httpclient;
HttpPost httppost = new HttpPost(Constants.BASEURL
+ "login.pl");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
2);
nameValuePairs.add(new BasicNameValuePair("userid", mEmail));
nameValuePairs
.add(new BasicNameValuePair("password", mPassword));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
String responseAsText = EntityUtils.toString(response
.getEntity());
jsonStr = responseAsText.toString();
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
d = jsonObj.getJSONObject(TAG_D);
success = d.getString(TAG_SUCCESS);
error = d.getString(TAG_ERROR);
} catch (JSONException e) {
runOnUiThread(new Runnable() {
public void run() {
error = null;
down = true;
}
});
return false;
}
} else {
Log.e("ServiceHandler",
"Couldn't get any data from the url");
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
if (success == "true") {
httppost = new HttpPost(Constants.BASEURL + "drivers.pl");
try {
// set entities here ...
HttpResponse response = httpclient.execute(httppost);
String responseAsText = EntityUtils.toString(response
.getEntity());
String driverJson = responseAsText.toString();
...