File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
library/src/main/java/com/loopj/android/http Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -166,10 +166,8 @@ public String getCharset() {
166
166
* Creates a new AsyncHttpResponseHandler
167
167
*/
168
168
public AsyncHttpResponseHandler () {
169
- // Set up a handler to post events back to the correct thread if possible
170
- if (Looper .myLooper () != null ) {
171
- handler = new ResponderHandler (this );
172
- }
169
+ // Init Looper by calling postRunnable without argument
170
+ postRunnable (null );
173
171
}
174
172
175
173
/**
@@ -310,9 +308,19 @@ protected void sendMessage(Message msg) {
310
308
* @param runnable runnable instance, can be null
311
309
*/
312
310
protected void postRunnable (Runnable runnable ) {
313
- if (runnable != null ) {
311
+ boolean missingLooper = null != Looper .myLooper ();
312
+ if (missingLooper ) {
313
+ Looper .prepare ();
314
+ }
315
+ if (null == handler ) {
316
+ handler = new ResponderHandler (this );
317
+ }
318
+ if (null != runnable ) {
314
319
handler .post (runnable );
315
320
}
321
+ if (missingLooper ) {
322
+ Looper .loop ();
323
+ }
316
324
}
317
325
318
326
/**
@@ -370,7 +378,7 @@ byte[] getResponseData(HttpEntity entity) throws IOException {
370
378
if (contentLength > Integer .MAX_VALUE ) {
371
379
throw new IllegalArgumentException ("HTTP entity too large to be buffered in memory" );
372
380
}
373
- int buffersize = (contentLength < 0 ) ? BUFFER_SIZE : (int ) contentLength ;
381
+ int buffersize = (contentLength < 0 ) ? BUFFER_SIZE : (int ) contentLength ;
374
382
try {
375
383
ByteArrayBuffer buffer = new ByteArrayBuffer (buffersize );
376
384
try {
You can’t perform that action at this time.
0 commit comments