,比如我有以下的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