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?
- Build a "request queue" Requestqueue
- Build request requests, support Stringrequest,jsonrequest, and can customize the Ask
- Constructs a callback listener, which is called after the request processing is complete.
- 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