diff options
author | Ficus Kirkpatrick <ficus@android.com> | 2013-05-21 19:17:57 -0700 |
---|---|---|
committer | Ficus Kirkpatrick <ficus@android.com> | 2013-05-21 19:17:57 -0700 |
commit | f5bea0d0871b65cb63149f2f8d1231345b1a13f2 (patch) | |
tree | f8e13295ebca857554becd98d2c995913dc0bdc3 /src | |
parent | b49c1196d7898f49d97ce75560e8b4c110cee335 (diff) | |
download | volley-f5bea0d0871b65cb63149f2f8d1231345b1a13f2.tar.gz |
Allow custom HttpStack in Volley.newRequestQueue.
Add a variant method that allows the user to pass in
an HttpStack to be passed to BasicNetwork. Makes using
alternative stacks like OkHttp easier.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/volley/toolbox/Volley.java | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/com/android/volley/toolbox/Volley.java b/src/com/android/volley/toolbox/Volley.java index bba1153..1304045 100644 --- a/src/com/android/volley/toolbox/Volley.java +++ b/src/com/android/volley/toolbox/Volley.java @@ -36,9 +36,10 @@ public class Volley { * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link Context} to use for creating the cache dir. + * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ - public static RequestQueue newRequestQueue(Context context) { + public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; @@ -50,13 +51,14 @@ public class Volley { } catch (NameNotFoundException e) { } - HttpStack stack; - if (Build.VERSION.SDK_INT >= 9) { - stack = new HurlStack(); - } else { - // Prior to Gingerbread, HttpUrlConnection was unreliable. - // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html - stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); + if (stack == null) { + if (Build.VERSION.SDK_INT >= 9) { + stack = new HurlStack(); + } else { + // Prior to Gingerbread, HttpUrlConnection was unreliable. + // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html + stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); + } } Network network = new BasicNetwork(stack); @@ -66,4 +68,14 @@ public class Volley { return queue; } + + /** + * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. + * + * @param context A {@link Context} to use for creating the cache dir. + * @return A started {@link RequestQueue} instance. + */ + public static RequestQueue newRequestQueue(Context context) { + return newRequestQueue(context, null); + } } |