【发布时间】:2016-05-26 11:53:07
【问题描述】:
例如我有以下 AsyncTask:
private class MyAsyncTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Void doInBackground(Void... params) {
try {
//some code that may throws exception
return true;
} catch (IOException ex) {
return false;
}
}
@Override
protected void onPostExecute(Boolean param){
if (!param) {
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
builder.setMessage("Error");
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//I want to retry MyAsyncTask here
}
});
builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
}
执行此操作的最佳做法是什么?我怕递归这段代码。
【问题讨论】:
-
在这里使用 Handler 和 Thread 模式,年轻的 skywa1ker
标签: android