Android Development (40) volley-googlei02013 "Fast, Simple network communication Library" on the preliminary

Source: Internet
Author: User

What is volley

On Google I/O 2013, Volley was released. Volley is a network communication library on the Android platform that makes network communication faster, simpler, and more robust.
This is the origin of the volley name: a burst or emission of many things or a large amount at once

Characteristics

Supports JSON, images, binary text, memory and disk caching, powerful customization capabilities, Debug and trace Tools

How do I get it?

I put the compiled HTTP://YUNPAN.CN/CG7S8AWFTBSMP access password on the cloud disk B1BF

How to use it?
    1. Build a "request queue" Requestqueue
    2. Build request requests, support Stringrequest,jsonrequest, and can customize the Ask
    3. Constructs a callback listener, which is called after the request processing is complete.
    4. To add a request to a queue
Demo Code

Simple HTTP Way of Get Demo:

 Public classSimplegetactivityextendsActivity { requestqueue mrequestqueue;    TextView txt_msg; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.simple_get); Txt_msg=(TextView) Findviewbyid (r.id.txt_msg); Mrequestqueue = Volley.newrequestqueue ( this); }     Public voidBtn1onclick (View v) {String URL= "Http://www.baidu.com"; stringrequest req = new stringrequest (method.get, URL, Responselistener, merrorlistener);    Mrequestqueue.add (req); } Listener <String>Responselistener =NewListener<string>() {@Override Public voidonresponse (String str1) {txt_msg.settext (STR1);       }    }; Errorlistener Merrorlistener=NewErrorlistener () {@Override Public voidonerrorresponse (Volleyerror volleyerror) {Toast.maketext (Getbasecontext (), Volleyerror.getmes Sage (),0). Show (); }    };}

Send parameters using Post

 Public classParaspostactivityextendsActivity {requestqueue mrequestqueue;    TextView txt_msg; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_paras_post); Txt_msg=(TextView) Findviewbyid (r.id.txt_msg); Mrequestqueue= Volley.newrequestqueue ( This); }     Public voidBtn1onclick (View v) {String URL=Constants.url_for_demo1; Stringrequest req=Newstringrequest (method.post, URL, Responselistener, merrorlistener) {@Override 
    protected Map<string, string> Getparams () throws Authfailureerror {return new Apiparams (). With ("Key1", "V1"). With ("Key2", "V2");        }        };    Mrequestqueue.add (req); } Listener<String> Responselistener =NewListener<string>() {@Override Public voidonresponse (String str1) {txt_msg.settext (STR1);        }    }; Errorlistener Merrorlistener=NewErrorlistener () {@Override Public voidonerrorresponse (Volleyerror volleyerror) {Toast.maketext (Getbasecontext (), Volleyerror.getmes Sage (),0). Show (); }    };}

Note that when a parameter is passed, it is implemented by an anonymous class, overloading the Getparams method

Reference:

http://blog.csdn.net/t12x3456/article/details/9221611

Me.storm.volley Example

Android Development (40) volley-googlei02013 "Fast, Simple network communication Library" on the preliminary

Related Article

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.