Use of Google Open Source Library-volley

Source: Internet
Author: User

First, what is volley?

Volley is a HTTP library that makes networking for Android apps easier and most importantly, faster.  Volley is available through the open AOSP repository. (The above means: volley is a tool for dealing with Android network communication, it can be the network communication in Android more fast and efficient)

--->url (https://developer.android.com/training/volley/index.html)

Second, how to quote volley in your own project?

  

PS: The above describes how volley is used, you need to clone it locally using the Git tool, and then use Eclipse ADT to convert it to a jar file for use

Third, the use of volley explanation

3.1 Using the valley to implement JSON string requests

/** * Get JSON data via volley */public void Getjsonvolley () {Requestqueue requestqueue=volley.newrequestqueue ( this);  Used to get a volley request object String jsondateurl= "http://www.imooc.com/api/teacher?type=4&num=30"; Requested URL//(request., URL, Listener, Errorlistener)//--> requests, request link, successful request, error received request Jsonobjectreques                T jsonobjectrequest=new jsonobjectrequest (Request.Method.GET, Jsondateurl, NULL,//successfully obtained requested data                            New Response.listener<jsonobject> () {public void Onresponse (Jsonobject Response) {                        System.out.println ("response=" +response);                        }},//exception gets requested data new Response.errorlistener () { public void Onerrorresponse (Com.android.volley.VolleyError arg0) {System.out.println ("Sorry, there is a problem"                        );        }                }            ); RequestQueue.add (jsonobjectrequest); Add the current request to the request queue}

3.2 Loading pictures asynchronously using volley

 /** * Use volley to load images asynchronously * url:http://img.mukewang.com//55237dcc0001128c06000338.jpg */public void LoadImage Volley () {String imageurl= "http://img.mukewang.com//55237dcc0001128c06000338.jpg";//Picture link Requestqueue requ Estqueue=volley.newrequestqueue (this); Create volley Request Object final lrucache<string, bitmap> lrucache=new lrucache<string,bitmap> (20);  Create a cache object cache size of Imagecache imagecache=new Imagecache () {@Override public void            Putbitmap (String key, Bitmap value) {lrucache.put (key, value); } @Override Public Bitmap getbitmap (String key) {return Lrucache.get (key            );        }        };                Use Imageload to load images, load parameters (request, image cache) Imageloader imageloader=new imageloader (Requestqueue, Imagecache); Parameter (control name, can't find time picture, unusual time picture) Imagelistener Listener=imageloader.getimagelistener (IMG, r.drawable.ic_launchEr, r.drawable.ic_launcher);    Imageloader.get (IMAGEURL, listener); }

--Using this method allows us to get a picture of the network

Iv. Analysis and summary

The use of volley greatly reduces the code in our asynchronous acquisition of network data, making it faster and more efficient to get data from the network

V. Related JAR packages and links

5.1 Volley.jar (http://yunpan.cn/cdYYMFt33Ky7d access password e9b4)

5.2 Volley Official introduction (https://developer.android.com/training/volley/index.html)

Use of Google Open Source Library-volley

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.