【发布时间】:2011-12-19 01:27:06
【问题描述】:
我一直在使用Callable,但现在我需要在call 方法中使用参数的函数。我知道这不是call 的能力,我该怎么做呢?
我目前拥有的(错误的):
AsyncTask async = new MyAsyncTask();
async.finished(new Callable(param) {
// the function called during async.onPostExecute;
doSomething(param);
});
async.execute(url);
MyAsyncTask:
...
@Override
protected void onPostExecute(JSONObject result) {
//super.onPostExecute(result);
if(result != null) {
try {
this._finished.call(result); // not valid because call accepts no params
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void finished(Callable<Void> func) {
this._finished = func;
}
...
【问题讨论】: