public void cancelTag(Object tag) { Dispatcher dispatcher = mClient.dispatcher(); List<Call> calls = dispatcher.queuedCalls(); for (Call call : calls) { if (call.request().tag().equals(tag)) { call.cancel(); } } calls = dispatcher.runningCalls(); for (Call call : calls) { if (call.request().tag().equals(tag)) { call.cancel(); } } }
/** * 取消相同的tag请求 * * @param tag */ public static void cancelSameTagCall(Object tag) { if (mClient != null) { Dispatcher dispatcher = mClient.dispatcher(); for (Call call : dispatcher.queuedCalls()) { if (tag.equals(call.request().tag())) { call.cancel(); } } for (Call call : dispatcher.runningCalls()) { if (tag.equals(call.request().tag())) { call.cancel(); } } setCancel(true); } else { Logger.e(TAG, "cancelSameTagCall mClient 为 null"); } }