Volley, networking for android.

This post is outdated and I urge you to go have a look at the official google training material instead.

Most projects I have worked on needed some sort of network engine, and in most cases we needed something that could pull json data from a rest api over http and fetch images and thumbnails. Volley is a lib that does just that. Here are some official links and my demo implementation showing of the most basic features of Volley. Google IO 2013 talk on Volley The Volley manual My test implementation using Volley In the example linked above there is code in a few places that uses Volley. The most interesting parts are in the adapters, particularly in the details adapter where we fetch a image by just assigning a url to a NetworkImageView.

NetworkImageView niw = ((NetworkImageView)getActivity().findViewById(R.id.demo_item_details_image));
niw.setImageUrl(demoItem.getImage(), mImageLoader);

Can’t get much easier than that I believe.   All in all, I have found Volley to be very easy to use and it looks like a big time-saver, both during development and maintenance of a Android app.

This Post Has 12 Comments

  1. Alexander

    Thanks for your article Carl-Emil! :-)
    Volley is definitely a good start for Android team by providing a robust HTTP communication and image download & caching library!
    However, they both seem to me not very mature.

    While HTTP part of Volley is pretty good and flexible, there are very strong libraries from community such as https://github.com/octo-online/robospice, https://github.com/koush/ion, etc.
    Robospice is awesome by the way: we used it on a lot of projects, and it’s just great!

    Images loading?
    https://github.com/koush/ion, https://code.google.com/p/android-query, https://github.com/nostra13/Android-Universal-Image-Loader,
    All of them have more images loading specific features and options. And you even shouldn’t use NetworkImageView subclass. ImageView from SDK is good enough!
    So seems again – Volley is not the best choice here.

    What do you think? Will you use Volley for HTTP and images loading at your new Jayway Android projects?

    1. Carl-Emil Kjellstrand

      Hi Alexander,

      Thank for your comments! Will look into Robospice and ion as well as the image loading library’s you suggested.
      The reason I like Volley is that it’s so easy to use and does both images and ‘text’ data. Perhaps one of the alternatives proves to be even better!

      Regarding the NetworkImageView subclass, perhaps you missed the point of it. It handles the downloading and caching of images all by itself. You as a user/developer don’t have to pay attention to the fact that your downloading a image anymore (almost). Just set the url and the NetworkImageView handles the rest. Or am I missing some feature of the Android sdk ImageView class here?

      Br Carl-Emil

      1. Alexander

        Hi Carl-Emil,
        I didn’t miss the point of NetworkImageView. ;-)
        It’s simple to use – no doubts! However, replacing each and every web based ImageView of the app with NetworkImageView – this probably too intrusive. At least for me. While most image loading & caching libs works well with ImageView itself. E.g. Picasso: Picasso.with(context).load(url).resize(100, 100).centerCrop().into(imageView);

        p.s. by the way, if you like to have combined images and HTTP support into one library, then you should definitely check out https://github.com/koush/ion and https://code.google.com/p/android-query – both of them have good set of features for images and HTTP related stuff. :-)

  2. Tobias Ericsson

    Nice, short and concise article. I also find it easy to use and as you say – a big time saver.

  3. Sudheesh B Nair

    Thanks for your article and Test code.
    I think the cache size we need to pass should be in Bytes instead of KB.
    int cacheSize = memoryClass * 1024 * 1024 / 4;
    instead of
    int cacheSize = memoryClass * 1024 / 4;
    Is it right?

    1. Carl-Emil Kjellstrand

      We pass this value around a bit, where do you think it’s wrong?

      1. Sudheesh B Nair

        Then it’s OK. When I used this value, my list view images are requesting each time when the images get focus on scrolling. So I changed the that value in to Bytes. :)

        1. Sudheesh B Nair

          If I use 1/4 of available memory, will it cause out of memory in normal case? Is it a good practice?

          1. Carl-Emil Kjellstrand

            Hi Sudheesh,

            What amount of memory to use for caching images would depend on what other things your application is doing that uses memory. But 1/4 or 1/8 of the total memory that your app is given by the system sounds reasonable to me.
            Br Carl

          2. Sudheesh B Nair

            Thanks a lot Carl-Emil.
            I understood your point. Thanks again for spending your time for me and sharing your thoughts.

  4. Sebastian Cheung

    Hi Carl,

    How would you modify your code to parse in and display JsonArray for:


    event: images

    from the URL:




    1. Carl-Emil Kjellstrand

      Hi Sebastian, sorry for the delayed answer. I just put together a example of how to parse the data you where referring to. Didn’t want to try to explain it in details without a example, and i think the example is more or less self explanatory :)
      So do have a look at the branch i created in github for you with the example, hope it will help!


Leave a Reply