本文整理了Java中com.android.volley.Request.cancel
方法的一些代码示例,展示了Request.cancel
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.cancel
方法的具体详情如下:
包路径:com.android.volley.Request
类名称:Request
方法名:cancel
[英]Mark this request as canceled. No callback will be delivered.
[中]将此请求标记为已取消。不会发送回拨。
代码示例来源:origin: bumptech/glide
@Override
public void cancel() {
Request<byte[]> local = request;
if (local != null) {
local.cancel();
}
}
代码示例来源:origin: chentao0707/SimplifyReader
/**
* Detatches the bitmap container from the request and cancels the request if no one is
* left listening.
* @param container The container to remove from the list
* @return True if the request was canceled, false otherwise.
*/
public boolean removeContainerAndCancelIfNecessary(ImageContainer container) {
mContainers.remove(container);
if (mContainers.size() == 0) {
mRequest.cancel();
return true;
}
return false;
}
}
代码示例来源:origin: mcxiaoke/android-volley
/**
* Detatches the bitmap container from the request and cancels the request if no one is
* left listening.
* @param container The container to remove from the list
* @return True if the request was canceled, false otherwise.
*/
public boolean removeContainerAndCancelIfNecessary(ImageContainer container) {
mContainers.remove(container);
if (mContainers.size() == 0) {
mRequest.cancel();
return true;
}
return false;
}
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
/**
* Detatches the bitmap container from the request and cancels the request if no one is
* left listening.
* @param container The container to remove from the list
* @return True if the request was canceled, false otherwise.
*/
public boolean removeContainerAndCancelIfNecessary(ImageContainer container) {
mContainers.remove(container);
if (mContainers.size() == 0) {
mRequest.cancel();
return true;
}
return false;
}
}
代码示例来源:origin: mcxiaoke/android-volley
@Override
public void cancel() {
cancel_called = true;
super.cancel();
}
代码示例来源:origin: chentao0707/SimplifyReader
@Override
public synchronized boolean cancel(boolean mayInterruptIfRunning) {
if (mRequest == null) {
return false;
}
if (!isDone()) {
mRequest.cancel();
return true;
} else {
return false;
}
}
代码示例来源:origin: mcxiaoke/android-volley
@Override
public synchronized boolean cancel(boolean mayInterruptIfRunning) {
if (mRequest == null) {
return false;
}
if (!isDone()) {
mRequest.cancel();
return true;
} else {
return false;
}
}
代码示例来源:origin: chentao0707/SimplifyReader
/**
* Cancels all requests in this queue for which the given filter applies.
* @param filter The filtering function to use
*/
public void cancelAll(RequestFilter filter) {
synchronized (mCurrentRequests) {
for (Request<?> request : mCurrentRequests) {
if (filter.apply(request)) {
request.cancel();
}
}
}
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
@Override
public void cancel() {
cancel_called = true;
super.cancel();
}
代码示例来源:origin: mcxiaoke/android-volley
/**
* Cancels all requests in this queue for which the given filter applies.
* @param filter The filtering function to use
*/
public void cancelAll(RequestFilter filter) {
synchronized (mCurrentRequests) {
for (Request<?> request : mCurrentRequests) {
if (filter.apply(request)) {
request.cancel();
}
}
}
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
@Override
public synchronized boolean cancel(boolean mayInterruptIfRunning) {
if (mRequest == null) {
return false;
}
if (!isDone()) {
mRequest.cancel();
return true;
} else {
return false;
}
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
/**
* Cancels all requests in this queue for which the given filter applies.
* @param filter The filtering function to use
*/
public void cancelAll(RequestFilter filter) {
synchronized (mCurrentRequests) {
for (Request<?> request : mCurrentRequests) {
if (filter.apply(request)) {
request.cancel();
}
}
}
}
代码示例来源:origin: mcxiaoke/android-volley
@Test public void cancelAll_onlyCorrectTag() throws Exception {
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 0, mDelivery);
Object tagA = new Object();
Object tagB = new Object();
Request req1 = mock(Request.class);
when(req1.getTag()).thenReturn(tagA);
Request req2 = mock(Request.class);
when(req2.getTag()).thenReturn(tagB);
Request req3 = mock(Request.class);
when(req3.getTag()).thenReturn(tagA);
Request req4 = mock(Request.class);
when(req4.getTag()).thenReturn(tagA);
queue.add(req1); // A
queue.add(req2); // B
queue.add(req3); // A
queue.cancelAll(tagA);
queue.add(req4); // A
verify(req1).cancel(); // A cancelled
verify(req3).cancel(); // A cancelled
verify(req2, never()).cancel(); // B not cancelled
verify(req4, never()).cancel(); // A added after cancel not cancelled
}
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
@Test public void cancelAll_onlyCorrectTag() throws Exception {
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 0, mDelivery);
Object tagA = new Object();
Object tagB = new Object();
Request req1 = mock(Request.class);
when(req1.getTag()).thenReturn(tagA);
Request req2 = mock(Request.class);
when(req2.getTag()).thenReturn(tagB);
Request req3 = mock(Request.class);
when(req3.getTag()).thenReturn(tagA);
Request req4 = mock(Request.class);
when(req4.getTag()).thenReturn(tagA);
queue.add(req1); // A
queue.add(req2); // B
queue.add(req3); // A
queue.cancelAll(tagA);
queue.add(req4); // A
verify(req1).cancel(); // A cancelled
verify(req3).cancel(); // A cancelled
verify(req2, never()).cancel(); // B not cancelled
verify(req4, never()).cancel(); // A added after cancel not cancelled
}
}
代码示例来源:origin: mcxiaoke/android-volley
/**
* Verify RequestFinishedListeners are informed when requests are canceled
*
* Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
*/
@Test public void add_requestFinishedListenerCanceled() throws Exception {
RequestFinishedListener listener = mock(RequestFinishedListener.class);
Request request = new MockRequest();
Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
@Override
public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
Thread.sleep(200);
return mock(NetworkResponse.class);
}
};
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
when(mMockNetwork.performRequest(request)).thenAnswer(delayAnswer);
queue.addRequestFinishedListener(listener);
queue.start();
queue.add(request);
request.cancel();
verify(listener, timeout(100)).onRequestFinished(request);
queue.stop();
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
/**
* Verify RequestFinishedListeners are informed when requests are canceled
*
* Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
*/
@Test public void add_requestFinishedListenerCanceled() throws Exception {
RequestFinishedListener listener = mock(RequestFinishedListener.class);
Request request = new MockRequest();
Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
@Override
public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
Thread.sleep(200);
return mock(NetworkResponse.class);
}
};
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
when(mMockNetwork.performRequest(request)).thenAnswer(delayAnswer);
queue.addRequestFinishedListener(listener);
queue.start();
queue.add(request);
request.cancel();
verify(listener, timeout(100)).onRequestFinished(request);
queue.stop();
}
代码示例来源:origin: panxw/android-volley-manager
@Override
public void cancel() {
if (this.mRequest != null) {
this.mRequest.cancel();
}
}
代码示例来源:origin: panxw/android-volley-manager
@Override
public synchronized boolean cancel(boolean mayInterruptIfRunning) {
if (mRequest == null) {
return false;
}
if (!isDone()) {
mRequest.cancel();
return true;
} else {
return false;
}
}
代码示例来源:origin: xuningjack/AndroidNet
@Override
public synchronized boolean cancel(boolean mayInterruptIfRunning) {
if (mRequest == null) {
return false;
}
if (!isDone()) {
mRequest.cancel();
return true;
} else {
return false;
}
}
代码示例来源:origin: MewX/light-novel-library_Wenku8_Android
@Override
public synchronized boolean cancel(boolean mayInterruptIfRunning) {
if (mRequest == null) {
return false;
}
if (!isDone()) {
mRequest.cancel();
return true;
} else {
return false;
}
}
内容来源于网络,如有侵权,请联系作者删除!