我正在使用 Bolts framework在我的安卓项目中。看了好几遍文档,还是搞不懂continueWith()和onSuccess()的区别,因为回调方法和返回值都是一样的。例如,
Task task = ParseGeoPoint.getCurrentLocationInBackground(10*1000);
这两种方法有什么区别?
task.onSuccess(new Continuation<ParseGeoPoint, Object>() {
@Override
public Object then(Task<ParseGeoPoint> task) throws Exception {
Log.d(TAG, "task done");
return null;
}
});
task.continueWith(new Continuation<ParseGeoPoint, Object>() {
@Override
public Object then(Task<ParseGeoPoint> task) throws Exception {
Log.d(TAG, "task done");
return null;
}
});
最佳答案
基本上,onSuccess()
只是在调用完成且没有错误时被调用,正如其名称所示。另一方面,始终调用 continueWith()
,即使在失败的情况下也是如此。因此,如果您只对检索成功请求的结果感兴趣,请使用 onSuccess()
,如果您还希望能够处理失败的请求,请使用 continueWith()
。
关于android - Bolts 框架中的 continueWith() 和 onSuccess() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27917312/