2

我在我的 Android 项目中使用Bolts 框架。文档看了好几遍,还是对 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;
    }
});
4

1 回答 1

4

基本上,onSuccess()正如其名称所示,当调用完成且没有错误时才调用它。另一方面,continueWith()总是调用,即使在失败的情况下。因此,onSuccess()当您只对检索成功请求的结果感兴趣时使用,continueWith()如果您希望也能够处理失败的请求,请使用。

于 2015-02-18T01:43:00.333 回答