android - Bolts 框架中的 continueWith() 和 onSuccess() 有什么区别?

标签 android bolts-framework

我正在使用 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/

相关文章:

android - 单元测试 Bolts Tasks With Continuations (Android)

ios - BFTASK中的方法即使完成任务也会被延迟

android - 如何知道用户是否观看了广告?

安卓深度链接

java - 在android上从天数中获取年、月、日

android - 在 Android 上定位 SQLite 数据库文件

ios - bolt Apple Mach-O 链接器错误

ios - bolt 异步框架方法无法识别

Android 从父 Activity 中关闭子 Activity

java - Android:如何将查询与来自 Parse.com 的 Bolt 同步?