执行AsyncTask时遇到问题:onPostExecute()方法只执行一次。第二次没有更新。
记录:
05-31 23:15:35.261 31682-32136/com.stimulus D/result45: Qu'est ce que c'est ?
05-31 23:15:35.301 31682-31682/com.stimulus D/result50: Qu'est ce que c'est ?
05-31 23:15:38.201 31682-31878/com.stimulus D/result45: C'est quoi ?
05-31 23:15:38.261 31682-31682/com.stimulus D/result50: Qu'est ce que c'est ?
代码:
class NextQuestionChooseAsync extends AsyncTask<String, Void, ArrayList<String>> {
private Dialog loadingDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
loadingDialog = ProgressDialog.show(QuestionActivity.this, "Please wait", "Loading...");
}
@Override
protected ArrayList<String> doInBackground(String... params) {
InputStream is = null;
email = (String) getIntent().getSerializableExtra("email");
password = (String) getIntent().getSerializableExtra("password");
idSession = (int) getIntent().getSerializableExtra("idSession");
String json = null;
String result = null;
String question = null;
try {
//Http request to communicate with our system
HttpClient httpClient = new DefaultHttpClient();
List<BasicNameValuePair> parameters = new LinkedList<BasicNameValuePair>();
parameters.add(new BasicNameValuePair("idsession", String.valueOf(idSession)));
HttpGet httpGet = new HttpGet();
URI website = new URI("http://192.168.1.33:5001/nextquestion" + "?"+ URLEncodedUtils.format(parameters, "utf-8"));
httpGet.setURI(website);
String base64EncodedCredentials = Base64.encodeToString(
(email + ":" + password).getBytes(),
Base64.NO_WRAP);
Log.d("test",base64EncodedCredentials);
httpGet.setHeader("Authorization", "Basic " + base64EncodedCredentials);
HttpResponse response = httpClient.execute(httpGet);
statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
Log.d("result1", result);
//Manage JSON result
JSONObject jsonObject = new JSONObject(result);
question = jsonObject.getString("question");
Log.d("result45",question);
questionInformation.add(question);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
return questionInformation;
}
@Override
protected void onPostExecute(ArrayList<String> status) {
loadingDialog.dismiss();
String question = questionInformation.get(0);
Log.d("result50",question);
tv_title_question.setText(question);
}
}
NextQuestionChooseAsync nqca = new NextQuestionChooseAsync();
nqca.execute();
}
为什么第二次方法onPostExecute()中的值问题没有改变?
谢谢你的帮助。