File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
library/src/main/java/com/loopj/android/http Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1818
1919package com .loopj .android .http ;
2020
21+ import android .os .Looper ;
22+
2123import java .lang .ref .WeakReference ;
2224
2325/**
@@ -45,9 +47,21 @@ public RequestHandle(AsyncHttpRequest request) {
4547 * @return false if the request could not be cancelled, typically because it has already
4648 * completed normally; true otherwise
4749 */
48- public boolean cancel (boolean mayInterruptIfRunning ) {
49- AsyncHttpRequest _request = request .get ();
50- return _request == null || _request .cancel (mayInterruptIfRunning );
50+ public boolean cancel (final boolean mayInterruptIfRunning ) {
51+ final AsyncHttpRequest _request = request .get ();
52+ if (_request != null ) {
53+ if (Looper .myLooper () == Looper .getMainLooper ()) {
54+ new Thread (new Runnable () {
55+ @ Override
56+ public void run () {
57+ _request .cancel (mayInterruptIfRunning );
58+ }
59+ }).start ();
60+ } else {
61+ _request .cancel (mayInterruptIfRunning );
62+ }
63+ }
64+ return false ;
5165 }
5266
5367 /**
You can’t perform that action at this time.
0 commit comments