Search This Blog

Thursday 24 October 2013

Volley Android Networking Library : How to use Volley in your application and why?

In 2013 I/O Android session Ficus Kirkpatrick launched a new support for android developer. This is really cool library for networking operation.
If being android developer you stuck and searching for many question's answer related networking connection. Volley android sdk Gives the answer

Volley fixed these problems

1) All network requests happen serially
2) Rotating the screen will reload everything from the network
3) AsyncTasks stomp on recycled views
4) Compatibility problems on Froyo

Then curiously how's the documentation of android volley going to be !!Answer is Very simple

Volley Android library Implementation

Initializing Volley android before use anywhere in Constructer which called very first time

 // Somewhere common; app startup or adapter constructor  
 mRequestQueue = Volley.newRequestQueue(context);  
 mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache());  

Making request to URL which gives Json Response

 mRequestQueue.add(new JsonObjectRequest(Method.GET, url, null,  
 new Listener<JSONObject>() {  
 public void onResponse(JSONObject jsonRoot) {  
 mNextPageToken = jsonGet(jsonRoot, "next", null);  
 List<Items> items = parseJson(jsonRoot);  

Image Loading through volley contain two way

  •  Using ImageLoader class
 mImageLoader.get(image_url,imageView, R.drawable.loading, R.drawable.error);  
  • Using Volley Android Custom ImageView
 - <ImageView  
 + <  
 Java mImageView.setImageUrl(BASE_URL + item.image_url, mImageLoader);  

There are a lot more in Volley android. Download Sample and check them out

No comments:

Post a Comment

Feedback always help in improvement. If you have any query suggestion feel free to comment and Keep visiting my blog to encourage me to blogging

Android News and source code