lezorich / Ok-Volley

A combination of Square's OkHttp client and Volley Networking toolkit for Android. It also has Gson integrated and other small features, like a persistent cookie store.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ok-Volley

=========== Ok-Volley is an Android networking library which combines Square's OkHttp client with Volley Networking toolkit for Android. It already has implemented the common Volley classes:

  • VolleyManager: Singleton class that encapsulates RequestQueue and other volley functionality
  • GsonRequest: Volley adapter for json requests that will be parsed into Java objects by Gson.
  • LruBitmapCache: Implementation of an in-memory lru cache

Making a request


VolleyManager manager = VolleyManager.getInstance(getApplicationContext());
String url ="http://www.google.com";

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener() {
    @Override
    public void onResponse(String response) {
        // response
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(getApplicationContext(), "That didn't work!", 
            Toast.LENGTH_LONG).show();
    }
});

manager.getRequestQueue().add(stringRequest);

The library encapsulates Volley RequestQueue and other functionality in the VolleyManager class. VolleyManager is a singleton class, and VolleyManager.getInstance(context) returns the singleton instance. A key concept is that context must be the Application context, not an Activity context. This ensures that the RequestQueue will last for the lifetime of your app, instead of being recreated every time the activity is recreated (for example, when the user rotates the device).

About

A combination of Square's OkHttp client and Volley Networking toolkit for Android. It also has Gson integrated and other small features, like a persistent cookie store.

License:Apache License 2.0


Languages

Language:Java 100.0%