1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
class MyTask extends AsyncTask<.....>
{
public static interface OnTaskResults
{
public void onTaskFailed(Throwable t);
public void onTaskSucceeded(JSONArray array);
}
private Throwable error = null;
private OnTaskResults callback = null;
public MyTask(OnTaskResults cb) {
this.callback = cb;
}
public JSONArray doInBackground() {
JSONArray ret = null;
try {
...
} catch (Throwable t) {
this.error = t;
}
return ret;
}
public void onPostExecute(JSONArray result) {
if (result != null)
this.callback.onTaskSucceeded(result);
else
this.callback.onTaskFailed(this.error);
}
} |