,比如我有以下的AsyncTask:重试的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();
}
}
}
什么是做到这一点的最佳做法?我害怕这个代码递归。
使用处理程序和线程模式thingy在这里,年轻的skywa1ker – Reno 2011-03-17 08:25:06