Android Volley Examples

Posted / Публикувана 2013-05-20 in category / в категория: Android

In brief: here is the git project with the Volley examples/samples

 

In details:

Volley was announced just few days ago at the I/O 2013. It is a library/framework that helps the developers to create more easily applications that use network requests, and more precisely REST requests. I was very exited to give it a try but unfortunately I found that there are no examples and tutorials. Now, after experimenting with it, I will try to fill to some extend that gap.

Features of Volley:

  • Nice and easy API for executing REST requests;
  • unifies the mechanism for REST requests by abstracting the "bottom" layer, i.e. you don't care any more about HttpClient or HttpUrlConnection. On lower versions (<= GINGERBREAD) Volley uses AndroidHttpClient and no higher it uses HttpUrlConnection;
  • it is very fast. In the I/O presentation the guy states that they tested it at Google with several different apps and Volley was clear winner in all categories;
  • it is extensible -- you can use it as a basis to create your own custom type of requests (and response handling/parsing)

You can find the project with the examples at Github:

git clone git://github.com/ogrebgr/android_volley_examples.git

During the import of the project you may need to change the project name to "Volley Examples" otherwise you will end up with a project called "Act_Main".

You will need also the Volley itself:

git clone https://android.googlesource.com/platform/frameworks/volley

After importing Volley you may need to mark it as a "Library project" in order to include it in the example project.

 

Currently there are  6 examples:

In the next days I will add more examples.

All comments will be welcomed. If you wish to provide samples/examples that you want to be added to this project -- feel free to fork or write me an email  (address is here).

 

10 Responses to “Android Volley Examples”

  1. Bogdan Says:

    Excellent post, very helpful, looking forward for new examples

  2. Eman Says:

    Thanks for great examples. Looking forward for new ones.

    Is it possible to reconnect to running request in Volley? I have an activity which is populated via webservice. It fires new request onCreate but I dont want to discard and fire new request during orientation change. I cannot put these data in cache as well. I just need to survive orientation change and listen to result of original request.

  3. Ogi Bankov / Огнян Банков Says:

    @Eman
    Usually the result from the first request will be cached automatically for you so on recreate second request will get the data from the cache.
    As alternative you may declare your activity (in the manifest) to intercept the orientation change and handle it itself, i.e. to avoid recreation.
    Yet another alternative is to use fragments, fire the request from the fragment, and then after rotation to reconnect to the fragment (where meanwhile the result from the request is populated). I think that is the best solution.

  4. Eman Says:

    Thanks for your answer. I think that the last approach is the best one and most suitable for my use case.
    I used robospice before and there was possible to add listeners to running requests. It is possible to recreate this behavior in your Simple Request example. When you click on the button and change orientation, result is not delivered.

  5. none Says:

    Strange question, but how use Volley inside Fragment??

    mRequestQueue = Volley.newRequestQueue(getActivity());

    not working.

  6. Ogi Bankov / Огнян Банков Says:

    @none
    Is there a chance that you are calling getActivity() from a method that is before onActivityCreated() in the lifecycle of the fragment (like in onCreateView())? If yes: activity is not created yet, so getActivity() returns null. You will need to move it to onActivityCreated().

  7. none Says:

    You was right.

  8. Suri Says:

    I am getting this error
    The method newRequestQueue(Context) in the type Volley is not applicable for the arguments (Act_SsSslHttpClient, ExtHttpClientStack)

  9. Ogi Bankov / Огнян Банков Says:

    @suri
    You need to pull latest volley library. Older one does not have the appropriate constructor.

  10. Kumar Saurav Says:

    How can we use volley, the way this lib is used http://loopj.com/android-async-http/?

    Like, I want to define my base url then only append the endpoints of my web-service?

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Security Code: