@@ -117,13 +117,8 @@ public AsyncHttpResponseHandler() {
117117 * @param looper The looper to work with
118118 */
119119 public AsyncHttpResponseHandler (Looper looper ) {
120- this .looper = looper == null ? Looper .myLooper () : looper ;
121-
122- // Use asynchronous mode by default.
123- setUseSynchronousMode (false );
124-
125120 // Do not use the pool's thread to fire callbacks by default.
126- setUsePoolThread ( false );
121+ this ( looper == null ? Looper . myLooper () : looper , false );
127122 }
128123
129124 /**
@@ -133,17 +128,24 @@ public AsyncHttpResponseHandler(Looper looper) {
133128 * @param usePoolThread Whether to use the pool's thread to fire callbacks
134129 */
135130 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+ }
143133
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 ;
146146 }
147+
148+ this .usePoolThread = usePoolThread ;
147149 }
148150
149151 @ Override
0 commit comments