Volley--volley basic usage of Android network development (i)

Source: Internet
Author: User

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)

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.