I am using Volley library in my android app. It works fine, but I saw that OkHttp provides some more improvements also. I have integrated the OkHttp with Volley using :
Volley.newRequestQueue(mCtx.getApplicationContext(), new OkHttpStack());
My OkHttpStack class is :
public class OkHttpStack extends HurlStack {
private final OkUrlFactory mFactory;
public OkHttpStack() {
this(new OkHttpClient());
}
public OkHttpStack(OkHttpClient client) {
if (client == null) {
throw new NullPointerException("Client must not be null.");
}
mFactory = new OkUrlFactory(client);
}
@Override protected HttpURLConnection createConnection(URL url) throws IOException {
return mFactory.open(url);
}
}
1) Is it worth it? I have not noticed any noticeable improvement, but that may be because I have still not implemented SPDY support on my server.
2) On of the enhancement by OkHttp is response caching. However, volley does that too. Will I have any issues similar to this: https://github.com/square/okhttp/issues/680
3) Also, I am using two RequestQueues in Volley - one for Images & other for JSON. Should I use OkHttp with both queues?
I recommend you to switch to an stack that does not use okhttp-urlconnection like this one -> https://goo.gl/ZZRSQ5
1) Yes OkHttp has a lot of advantages like speed, HTTP/2, SPDY, saves bandwidth...
2) I haven't had any problem.
3) You only need one com.android.volley.RequestQueue for both. Take a look at this -> https://goo.gl/GMn3Ls
I've written about OkHttp + Volley + Gson here -> https://goo.gl/nl2DfN. I think might be interesting for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With