Master volley library
-
Upload
mahmoud-ramadan -
Category
Software
-
view
111 -
download
0
Transcript of Master volley library
Master Volley LibraryMahmoud Ramadan
IntroductionVolley is a networking library developed by Google and introduced during Google I/O 2013.
Volley abstracts the low level details of what HTTP client library is used.
Volley helps you focus on writing nice and clean RESTful HTTP requests.
Volley requests are done in another thread without blocking “main thread” to avoid the ANR(Application Not Responding).
Advantages and disadvantagesAdvantages
Much Faster
Cashes Eveything
Smal Metadata OPerations
Load Images From Network
DisadvantagesStreaming And Download Large Downloads
Volley MechanismMain Thread
Cache Thread
Network Thread
Getting Started To VolleyTo Import Volley to your App build.gradle file
To Use volley you just Create two Objects
Request QUeue
Request
dependencies { ... compile 'com.android.volley:volley:1.0.0'}
Request Types
Volley covers the Following Request Types
String Request
Image Request
Json Request
Request QUEUE
All request are placed first in queue and then processed like this:
RequestQueue mRequestQueue=Volley.newRequestQueue(this);
Centralized Place for your queueCreate class and name it “AppController” class which extends from Application
Public class AppController extends Application{
…..@Override Public void onCreate(){ super.onCreate();}……..}
Request priorityYou can set priority of request in volley.To do that you must ovveride getPriority() for the request class .
Priority.LOW
Priority.NORMAL
Priority.HIGH
Priority.IMMEDIATE
Cancelling requestsTo cancel request you must add tag for it first
And then cancel it
request.setTag(“tag”);//tag like GET for Get Request
requestQueue.cancelAll(“tag”);
Retray Policy and Time OutTo specify the amount of time out
make sure the maximum retry count is 1 so that volley does not retry the request after the timeout has been exceeded
request.setRetrayPolicy(new DefaultRetrayPolicy(20*1000,1,1.0f));
Error HandlingThe following is the list of exceptions in volley
AuthFailuarError
NetworkError
NoConnectionError
ParseError
ServerError
TimeOutError
Thanks