【发布时间】:2016-09-20 20:03:13
【问题描述】:
我浏览了 Retrofit 的官方 documentation 并决定在我的项目中实现类似的功能,以便用户始终可以选择取消下载文件,并且一切都会正常工作。实施适当的方法,其中未能规定以下:
service.upload1(file1, str, stringMap, new Callback<ImageUpload>() {
@Override
public void success(final ImageUpload imageUpload, Response response) {
mRecyclerView.post(new Runnable() {
@Override
public void run() {
...
});
}
@Override
public void failure(RetrofitError error) {
if (error.isCanceled()) {
Log.e(TAG, "request is cancelled");
} else {
Log.e(TAG, "other larger issue, i.e. no network connection?");
}
}
但在失败方法中用红色下划线isCanceled。我不明白是什么问题,因为我们最初提出的这个方法是 class Call(可能是因为骂我而不是 class Call 是 RetrofitError?)请告诉我如何解决。 我用的是改造 1.9,我不需要继续改造 2。
【问题讨论】:
-
isCanceled() 是该类型的现有方法,拼写是否正确?
-
您使用的是改造 1 还是改造 2?我认为 isCanceled 是在 Retrofit2 中引入的
-
仔细阅读文档............isCancelled() 方法属于 retrofit2.Call 类而不是 RetorfitError 类