Reputation: 3591
I have had some problems using HttpURLConnection before and the app I'm developing is >= 4.0. Is there any way to use the Apache 4.2 HttpClient (repackaged here) with Google Volley?
Currently I am using only the Apache 4.2 HttpClient but with the IO presentation of Volley I want to switch for speed and stability reasons.
Thanks in advance!
Upvotes: 2
Views: 3346
Reputation: 6073
The following should suffice:
mRequestQueue = Volley.newRequestQueue(context, new HttpClientStack(new DefaultHttpClient()));
Upvotes: 2
Reputation: 16235
The accepted answer has an error. It should extent the HttpClientStack rather than the HurlStack. The passed in httpclient is not used if extending the HUrlStack. You can check the PerformRequest method inside the Volley library and find that the client is not used.
Below is the correct code to do it.
public class ApacheStack extends HttpClientStack {
private final HttpClient client;
public ApacheStack(HttpClient client) {
super(client);
....
}
}
Upvotes: 1
Reputation: 10342
When you are instantiating your queue use the below one.
queue = Volley.newRequestQueue(getActivity(), new ApacheStack());
And then implement an ApacheStack that extends HurlStack like below and Override necessary functions.
public class ApacheStack extends HurlStack {
private final HttpClient client;
public ApacheStack() {
this(new HttpClient());
}
public ApacheStack(HttpClient client) {
if (client == null) {
throw new NullPointerException("Client must not be null.");
}
this.client = client;
}
}
Upvotes: 3