Web request tool based on Android volley

Source: Internet
Author: User

Web request tool based on Android volley. I. Description

Androidvolley,android Volley Core Library and extension project.
Androidvolleysample, the Network Request Tool sample project.
Release,jar package. Direct download

Second, volley basic processing flow:

1, the application initializes the volley.
2, volley create a requestqueue, Networkdispatcher group and network.
3, Requestqueue is a request queue, Requestqueue will create a executordelivery.
4, Networkdispatcher essence is thread, from the Requestqueue to take request, through the network to execute.
5, network is responsible for the processing of Web requests, the specific process to httpstack processing.
6, Httpstack Sub-httpurlconnection (sdk_int>=9) and httpclient and two ways.
7. Executordelivery is responsible for processing the request result and interacting with the main thread.
8, volley in the above 2-7 based on the addition of the cache and other additional processing links.

Third, the Network request tool

The Com.android.http package is expanded on the basis of Androidvolley, adding bytearrayrequest and Requestmanager, which facilitates the network request of character data type (Json/xml).

1. Initialize Requestmanager
public class Volleyapplication extends application {    @Override public    void OnCreate () {        super.oncreate (); C3/>requestmanager.getinstance (). Init (this);//Initialization Tool    }    @Override public    void Onterminate () {        Super.onterminate ();    }}
2. Using Requestmanager
public class Mainactivity extends Activity {private Loadcontroler loadcontroler = null;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Testpost ();    Testget (); }/** * POST request Test */private void Testpost () {Loadcontroler = Requestmanager.getinstance (). Post ("http    ://allthelucky.ap01.aws.af.cm/memoserver ", NULL, Requestlistener, 0); }/** * GET request Test */private void Testget () {Loadcontroler = Requestmanager.getinstance (). Get ("http://    Allthelucky.ap01.aws.af.cm/memoserver ", Requestlistener, 1);        }/** * Data response monitor */private Requestlistener Requestlistener = new Requestlistener () {@Override        public void ONrequest () {System.out.println ("onreqeust, start"); } @Override public void onsuccess (string response, string url, int actionid) {System.out.println("ActionId:" +actionid+ ", onsucess!\n" +response); } @Override public void OnError (string errormsg, string url, int actionid) {System.out.println ("        ActionId: "+actionid+", onerror!\n "+errormsg);    }    };        @Override public void onbackpressed () {super.onbackpressed ();    Loadcontroler.cancel (); }}

Http://git.oschina.net/winfirm/android-volley-manager

Web request tool based on Android 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.