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 18
18
19
19
package com .loopj .android .http ;
20
20
21
+ import android .os .Looper ;
22
+
21
23
import java .lang .ref .WeakReference ;
22
24
23
25
/**
@@ -45,9 +47,21 @@ public RequestHandle(AsyncHttpRequest request) {
45
47
* @return false if the request could not be cancelled, typically because it has already
46
48
* completed normally; true otherwise
47
49
*/
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 ;
51
65
}
52
66
53
67
/**
You can’t perform that action at this time.
0 commit comments