Skip to content

Commit 4f40cac

Browse files
committed
Added cancelAllRequests method, android-async-http#423
1 parent cb4d019 commit 4f40cac

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/src/main/java/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,26 @@ public void cancelRequests(Context context, boolean mayInterruptIfRunning) {
505505
}
506506
}
507507

508+
/**
509+
* Cancels all pending (or potentially active) requests. <p>&nbsp;</p> <b>Note:</b> This will
510+
* only affect requests which were created with a non-null android Context. This method is
511+
* intended to be used in the onDestroy method of your android activities to destroy all
512+
* requests which are no longer required.
513+
*
514+
* @param mayInterruptIfRunning specifies if active requests should be cancelled along with
515+
* pending requests.
516+
*/
517+
public void cancelAllRequests(boolean mayInterruptIfRunning) {
518+
for (List<RequestHandle> requestList : requestMap.values()) {
519+
if (requestList != null) {
520+
for (RequestHandle requestHandle : requestList) {
521+
requestHandle.cancel(mayInterruptIfRunning);
522+
}
523+
}
524+
}
525+
requestMap.clear();
526+
}
527+
508528
// [+] HTTP HEAD
509529

510530
/**

0 commit comments

Comments
 (0)