【问题标题】:How to cancel request by tag in retrofit 2?如何在改造 2 中按标签取消请求?
【发布时间】:2017-10-02 05:12:57
【问题描述】:

有没有办法像 Volley 一样在改造 2 中通过标签取消特定请求。 在 volley 中,我们可以通过这样做来取消请求。

sRequestQueue = Volley.newRequestQueue(appContext);


public void enqueueRequest(Request req) {
    sRequestQueue.add(req);
}


public void cancelTaggedRequests(String tag) {
    sRequestQueue.cancelAll(tag);
}

Retrofit 2.0 有没有类似的方法?

【问题讨论】:

    标签: android android-volley retrofit2 okhttp okhttp3


    【解决方案1】:

    您可以拨打call.cancel();取消请求

    另一种方式使用 RxJava 并创建订阅和取消订阅尊重的请求。

    if (subscription != null && !subscription.isUnsubscribed()) {
      subscription.unsubscribe();
    }
    

    【讨论】:

    • 如果是 RxJava,我们如何取消它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 2018-03-26
    • 1970-01-01
    相关资源
    最近更新 更多