我AsyncTask
用来做后台处理,即我从服务器获取数据并存储在List
indoInBackground()
方法中。我正在使用这个存储的数据onPostExecute()
。
我面临的问题是onPostExceute()
甚至在执行doInBackground()
完成之前就被执行。
有人可以建议可能出了什么问题吗?
代码:
AsyncTask<Void, Void, Void> read= new AsyncTask<Void, Void, Void>() {
ProgressDialog progress= new ProgressDialog(LastData.this);
ArrayList<String> testData;
DBAdapter db;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progress.setTitle("Please Wait");
testData= new ArrayList<String>();
db= new DBAdapter(LastData.this);
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.setMessage("Fetching Data !!");
progress.show();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
ParseQuery query = new ParseQuery("Details");
query.findInBackground(new FindCallback() {
public void done(List<ParseObject> dataList,
ParseException e) {
if (e == null) {
Log.d("Details", "Retrieved " + dataList.size()
+ " scores");
for (int idx = 0; idx < dataList.size(); idx++) {
data.add(dataList.get(idx).get("fname")
.toString());
}
} else {
System.out.println(e.getMessage());
}
for (int idx = 0; idx < data.size(); idx++) {
testData.add(data.get(idx));
}
System.out.println("size inside is " + testData.size());
}
});
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
progress.dismiss();
Toast.makeText(LastData.this, "Size is "+testData.size(), Toast.LENGTH_LONG).show();
}
};
read.execute();
Toast
onPostExecute()
甚至在doInBackground
方法执行之前就显示了 meassage in 。