@@ -117,13 +117,8 @@ public AsyncHttpResponseHandler() {
117
117
* @param looper The looper to work with
118
118
*/
119
119
public AsyncHttpResponseHandler (Looper looper ) {
120
- this .looper = looper == null ? Looper .myLooper () : looper ;
121
-
122
- // Use asynchronous mode by default.
123
- setUseSynchronousMode (false );
124
-
125
120
// Do not use the pool's thread to fire callbacks by default.
126
- setUsePoolThread ( false );
121
+ this ( looper == null ? Looper . myLooper () : looper , false );
127
122
}
128
123
129
124
/**
@@ -133,17 +128,24 @@ public AsyncHttpResponseHandler(Looper looper) {
133
128
* @param usePoolThread Whether to use the pool's thread to fire callbacks
134
129
*/
135
130
public AsyncHttpResponseHandler (boolean usePoolThread ) {
136
- // Whether to use the pool's thread to fire callbacks.
137
- setUsePoolThread (usePoolThread );
138
-
139
- // When using the pool's thread, there's no sense in having a looper.
140
- if (!getUsePoolThread ()) {
141
- // Use the current thread's looper.
142
- this .looper = Looper .myLooper ();
131
+ this (usePoolThread ? null : Looper .myLooper (), usePoolThread );
132
+ }
143
133
144
- // Use asynchronous mode by default.
145
- setUseSynchronousMode (false );
134
+ private AsyncHttpResponseHandler (Looper looper , boolean usePoolThread ) {
135
+ if (!usePoolThread ) {
136
+ Utils .asserts (looper != null , "use looper thread, must call Looper.prepare() first!" );
137
+ this .looper = looper ;
138
+ // Create a handler on current thread to submit tasks
139
+ this .handler = new ResponderHandler (this , looper );
140
+ } else {
141
+ Utils .asserts (looper == null , "use pool thread, looper should be null!" );
142
+ // If pool thread is to be used, there's no point in keeping a reference
143
+ // to the looper and handler.
144
+ this .looper = null ;
145
+ this .handler = null ;
146
146
}
147
+
148
+ this .usePoolThread = usePoolThread ;
147
149
}
148
150
149
151
@ Override
0 commit comments