1

如果 onPostExecute 无法从服务器加载数据,我想在对话框上显示重新加载按钮。那么如何在 AsyncTask 中重新启动或执行类似的操作?

4

3 回答 3

3

再次调用它:

new mAsyncTask.execute("");

当数据未成功加载时,在onPostExecute的某些 if 块中。

于 2012-12-06T09:25:24.390 回答
0

把它放在你的按钮的 onClickListener 中:

if(task.cancel(true)) {
    YourTask task = new YourTask(this);
    task.execute();
}

因此,在单击按钮时,您将尝试取消当前执行的任务并开始一个新任务。

于 2012-12-06T09:25:52.800 回答
0

要重新启动 AsyncTask,您需要创建 asynctask 的新实例并调用 execute();

@Override
protected void onPostExecute(Response result) {
    super.onPostExecute(result);
    new YourAsyncTask().execute();          
    }
}
于 2018-04-03T06:09:22.827 回答