master volley library

13
Master Volley Library Mahmoud Ramadan

Upload: mahmoud-ramadan

Post on 16-Apr-2017

111 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Master volley library

Master Volley LibraryMahmoud Ramadan

Page 2: Master volley library

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).

Page 3: Master volley library

Advantages and disadvantagesAdvantages

Much Faster

Cashes Eveything

Smal Metadata OPerations

Load Images From Network

DisadvantagesStreaming And Download Large Downloads

Page 4: Master volley library

Volley MechanismMain Thread

Cache Thread

Network Thread

Page 5: Master volley library

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'}

Page 6: Master volley library

Request Types

Volley covers the Following Request Types

String Request

Image Request

Json Request

Page 7: Master volley library

Request QUEUE

All request are placed first in queue and then processed like this:

RequestQueue mRequestQueue=Volley.newRequestQueue(this);

Page 8: Master volley library

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();}……..}

Page 9: Master volley library

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

Page 10: Master volley library

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”);

Page 11: Master volley library

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));

Page 12: Master volley library

Error HandlingThe following is the list of exceptions in volley

AuthFailuarError

NetworkError

NoConnectionError

ParseError

ServerError

TimeOutError

Page 13: Master volley library

Thanks