我正在创建异步任务,检索字符串数据:
View.OnClickListener btnClk = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (btnGetData.getId() == ((Button) v).getId()) {
Object obj = new FetchTask(Main.this).execute((Integer) null);
}
}
};
我的任务:
public class FetchTask extends AsyncTask<Object, Object, Object> {
private Context ctx;
private String xml;
public FetchTask(Context context) {
ctx = context;
}
@Override
protected void onPreExecute() {
DialogDownload_Ring = ProgressDialog.show(Main.this, "Download...",
"Fetching XML data...");
DialogDownload_Ring.setCancelable(true);
DialogDownload_Ring.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
cancel(true);
}
});
super.onPreExecute();
}
@Override
protected void onCancelled() {
super.onCancelled();
}
@Override
protected void onPostExecute(Object result) {
if (result instanceof Exception) {
DialogDownload_Ring.setMessage("Download failed!");
} else {
DialogDownload_Ring.setMessage("Succesfully Downloaded!");
}
DialogDownload_Ring.dismiss();
super.onPostExecute(result);
}
@Override
protected Object doInBackground(Object... params) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL_Local);
HttpResponse httpResponce = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponce.getEntity();
xml = EntityUtils.toString(httpEntity);
return xml;
} catch (Exception e) {
return e;
}
}
}
如何从 Object obj 中检索 xml 数据?obj.toString() 不工作。否则我创建 asynctask 字符串属性(扩展 AsyncTask 字符串、字符串、字符串)它正在工作但进度条在检索 xml 数据后启动,我也不明白。请帮帮我。PS对不起我的英语不好..