这是我从Asynctask
开始的班级:
public class HttpAsyncTaskSendData extends AsyncTask<String, Void, String> {
public interface SendDataCallback {
void onComplete(AsyncTask task,String nidSave, String guid);
void onError(String msg);
}
...
@Override
protected String doInBackground(String... urls) {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
return PostJson.POST(urls[0], urls[1]);
}
@Override
protected void onPostExecute(String result) {
if (result != null) {
...
dataCallback.onComplete(this,res.getString("NidSave"), guid);
} else {
dataCallback.onError("No response from server");
}
}
....
}
我在这样的活动中使用此类:
sendDataQueue.add(httpAsyncTaskSendData = new HttpAsyncTaskSendData(cur.getString(cur.getColumnIndex("Guid")),
cur.getString(cur.getColumnIndex("SendStateGps")), datasource, database1
, Housing, new HttpAsyncTaskSendData.SendDataCallback() {
@Override
public void onComplete(AsyncTask task ,String nidSave, String guid) {
if (task.getStatus().equals(AsyncTask.Status.FINISHED) &&
!nidSave.equals("00000000-0000-0000-0000-000000000000")) {
sendDataQueue.remove(task);
} else {
queueHasError = true;
}
if (!queueHasError) {
if (sendDataQueue.size() == 0) {
SendGps(nidSave, guid);
}
}
}
@Override
public void onError(String msg) {
queueHasError = true;
toastError(DetailsActivity.this, msg);
}
}).executeOnExecutor((AsyncTask.THREAD_POOL_EXECUTOR),
AppUtil.getConfig(DetailsActivity.this,
MainActivity.SETTING_GEO_SERVICE) + "SaveVisit/",
json.toString()));
我的问题是,为什么当我检查Asyncktask status时在onComplete
回调中处于Running
模式?并且不在Finnish
中。
我的onComplete
回调调用了onPostExecute
,在本节中,我的任务应该完成它的工作!!!但仍在运行吗?发生什么了,我有什么问题?
答案 0 :(得分:3)