Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use OkHttp with Volley library?

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?

like image 842
User31689 Avatar asked Jan 15 '15 09:01

User31689


1 Answers

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.

like image 137
Sotti Avatar answered Sep 22 '22 14:09

Sotti