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