1. Stringrequest usage
It is divided into 3 main steps:
(1), instantiate a Requestqueue object
(2), set the Stringrequest object parameter, and add the Stringrequest object to the Requestqueue queue
(3), execute Start () method
Public classStringactivityextendsActivity {PrivateTextView mtvshow; PrivateRequestqueue Requestqueue; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_string); Initview (); } Public voidInitview () {mtvshow=(TextView) Findviewbyid (r.id.tv_string); Requestqueue=Volley.newrequestqueue (Getbasecontext ()); Requestqueue.add (stringrequest); Requestqueue.start (); } /**stringrequest request, default is get*/ PublicStringrequest stringrequest =NewStringrequest ("http://www.baidu.com",NewListener<string>() {@Override Public voidOnresponse (String response) {//TODO auto-generated Method StubToast.maketext (Getbasecontext (), response, Toast.length_short). Show (); } }, NewErrorlistener () {@Override Public voidonerrorresponse (volleyerror error) {//TODO auto-generated Method StubLOG.E ("Stringrequest", error.tostring ()); } }); /**Stringrequest POST request, but need to rewrite anonymous class getparams ()*/stringrequest StringRequest1=NewStringrequest (Method.post, "http://www.baidu.com",NewListener<string>() {@Override Public voidOnresponse (String response) {//TODO auto-generated Method StubMtvshow.settext (response); } }, NewErrorlistener () {@Override Public voidonerrorresponse (volleyerror error) {//TODO auto-generated Method StubLOG.E ("Stringrequest", error.tostring ()); } }){ //functions that need to be rewritten to get arguments protectedMap<string,string> Getparams ()throwsAuthfailureerror {Map<string, string> map =NewHashmap<string, string>(); Map.put ("WD", "Get Started"); Map.put ("RSV_SPT", "Don't start."); returnmap; }; };}
2. Do not forget to join the network access rights
<uses-permission android:name= "Android.permission.INTERNET"/>
3. Reference Blog:
http://blog.csdn.net/guolin_blog/article/details/17482095/
http://blog.csdn.net/xyz_lmn/article/details/12165391
4, the first time to write a blog, what are the problems we have more advice!
Volley--volley basic usage of Android network development (i)