@@ -103,6 +103,50 @@ public abstract class AsyncHttpResponseHandler implements ResponseHandlerInterfa
103
103
private Header [] requestHeaders = null ;
104
104
private Looper looper = null ;
105
105
106
+ /**
107
+ * Creates a new AsyncHttpResponseHandler
108
+ */
109
+ public AsyncHttpResponseHandler () {
110
+ this (null );
111
+ }
112
+
113
+ /**
114
+ * Creates a new AsyncHttpResponseHandler with a user-supplied looper. If
115
+ * the passed looper is null, the looper attached to the current thread will
116
+ * be used.
117
+ *
118
+ * @param looper The looper to work with
119
+ */
120
+ public AsyncHttpResponseHandler (Looper looper ) {
121
+ this .looper = looper == null ? Looper .myLooper () : looper ;
122
+
123
+ // Use asynchronous mode by default.
124
+ setUseSynchronousMode (false );
125
+
126
+ // Do not use the pool's thread to fire callbacks by default.
127
+ setUsePoolThread (false );
128
+ }
129
+
130
+ /**
131
+ * Creates a new AsyncHttpResponseHandler and decide whether the callbacks
132
+ * will be fired on current thread's looper or the pool thread's.
133
+ *
134
+ * @param usePoolThread Whether to use the pool's thread to fire callbacks
135
+ */
136
+ public AsyncHttpResponseHandler (boolean usePoolThread ) {
137
+ // Whether to use the pool's thread to fire callbacks.
138
+ setUsePoolThread (usePoolThread );
139
+
140
+ // When using the pool's thread, there's no sense in having a looper.
141
+ if (!getUsePoolThread ()) {
142
+ // Use the current thread's looper.
143
+ this .looper = Looper .myLooper ();
144
+
145
+ // Use asynchronous mode by default.
146
+ setUseSynchronousMode (false );
147
+ }
148
+ }
149
+
106
150
@ Override
107
151
public URI getRequestURI () {
108
152
return this .requestURI ;
@@ -196,28 +240,6 @@ public String getCharset() {
196
240
return this .responseCharset == null ? DEFAULT_CHARSET : this .responseCharset ;
197
241
}
198
242
199
- /**
200
- * Creates a new AsyncHttpResponseHandler
201
- */
202
- public AsyncHttpResponseHandler () {
203
- this (null );
204
- }
205
-
206
- /**
207
- * Creates a new AsyncHttpResponseHandler with a user-supplied looper. If
208
- * the passed looper is null, the looper attached to the current thread will
209
- * be used.
210
- *
211
- * @param looper The looper to work with
212
- */
213
- public AsyncHttpResponseHandler (Looper looper ) {
214
- this .looper = looper == null ? Looper .myLooper () : looper ;
215
- // Use asynchronous mode by default.
216
- setUseSynchronousMode (false );
217
- // Do not use the pool's thread to run the handler.
218
- setUsePoolThread (false );
219
- }
220
-
221
243
/**
222
244
* Fired when the request progress, override to handle in your own code
223
245
*
0 commit comments