我在AsyncTask
类中未达到onPostExecute
。AsyncTask onPostExecute不输出
我调用任务这种方式,onClick
里面一个对话框:
new HelpfulTask().execute(passing);
注:当我将鼠标悬停在上面的代码中,我得到一个警告:
的通用阵列ArrayList是为参数varargs 创建的。
我不确定这是什么意思,如果这阻止我的任务甚至运行?
这里是任务代码:
protected class UnHelpfulTask extends
AsyncTask<ArrayList<String>, Void, ArrayList<String>> {
ArrayList<String> passed;
protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
passed = passing[0];
String url_select = "http://www.---.com/---/bad.php";
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("item", passed.get(0)));
param.add(new BasicNameValuePair("text", passed.get(1)));
param.add(new BasicNameValuePair("category", passed.get(2)));
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_select);
try {
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
// read content
is = httpEntity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
return null;
}
InputStream is = null;
String result = "";
protected void onPostExecute(Void v) {
Toast.makeText(getContext(), "You have voted this down!",
Toast.LENGTH_SHORT).show();
}
}
我得到上运行,并在onPostExecute
没有错误,敬酒从不显露。 (注意:这是ArrayAdapter.
里面的一个内部类)我还加了一杯烤面包,看看我的ArrayList
是否正确展开,并将其放在onPostExecute
中,但它从未显示过。
如何测试以查看此任务是否正在运行?
你的意思是'UnHelpfulTask'? – KhalidTaha