SlideShare a Scribd company logo
1 of 35
Volley: Easy, Fast
Networking for Android
Prepared by: Himanshu Saini
1. Introduction To Volley
1. Volley is an HTTP library that makes networking for Android
apps easier and most importantly, faster.
2. Volley is developed by Google & introduced during Google
I/O 2013.
3. Volley is available through the AOSP or GitHub.
 Using Volley In Your Project
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-
v7:24.0.0'
compile 'com.android.volley:volley:1.0.0'
}
2. Benefits of Volley
 Automatic scheduling of network requests.
 Multiple concurrent network connections.
 Support for request prioritization.
 Cancellation request API. You can cancel a single request, or
you can set blocks or scopes of requests to cancel.
 Ease of customization, for example, for retry and backoff.
 Strong ordering that makes it easy to correctly populate your UI
with data fetched asynchronously from the network.
 Debugging and tracing tools.
Comparison Between
AsyncTask
And
Volley
AsyncTask
Worker Thread
Main Thread
doInBackground()
Http Request
Http Response
 AsyncTask In Android
Worker Thread
Main Thread
doInBackground()
Http Request
Http Response
 AsyncTask In Android
Volley
Main
Thread
Cache Thread
Cache
Dispatcher
Network Thread
Request
Cash Miss
Request
Http Request
Http Response
Response
Response
Cache MemoryResponse
Response
Main
Thread
Cache Thread
Cache
Dispatcher
Network Thread
Request
Cash Hit
Cache Memory
Response
Request
Response
2. Sending a Simple Request
 Add the Internet permission
 Use newRequestQueue
 Send a RequestQueue
 Cancel a Request
2.1 Add the Internet Permission
 Add android.permission.INTERNET permission to app's
manifest
<uses-permission android:name="android.permission.INTERNET/>
2.2 Use newRequestQueue
 Volley provides a convenience method
Volley.newRequestQueue that sets up a RequestQueue for
you, using default values, and starts the queue.
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
2.3 Send a Request
 To send a request, you simply construct one and add it to
the RequestQueue object with add(StringRequest Object).
// Add the request to the RequestQueue.
queue.add(stringRequest);
Processing Send a Request
Example of RequestQueue and
Send Request
2.4 Cancel a Request
 To cancel a request, call cancelAll()on your Request object.
 We can call cancel a request in onStop() method of An
activtiy
mRequestQueue.cancelAll(Object Tag);
@Override
protected void onStop () {
super.onStop();
if (mRequestQueue != null) {
mRequestQueue.cancelAll(TAG);
}
}
Example
 Define your tag and add it to your requests.
Example (Contd.)
 In your activity's onStop() method, cancel all requests that
have this tag.
3. Making a Standard Request
 Introduction to Standard Request
 Request an Image
 Use ImageRequest
 Use ImageLoader and NetworkImageView
 Request JSON
3.1 Introduction to Standard
Request
 StringRequest: Specify a URL and receive a raw string in
response.
 ImageRequest: Specify a URL and receive an image in
response.
 JsonObjectRequest and JsonArrayRequest (both
subclasses of JsonRequest): Specify a URL and get a
JSON object or array (respectively) in response.
3.2 Request an Image
 Volley offers the following classes for requesting images.
These classes layer on top of each other to offer different
levels of support for processing images:
 ImageRequest—a canned request for getting an image at a
given URL and calling back with a decoded bitmap. It also
provides convenience features like specifying a size to resize
to.
 ImageLoader—a helper class that handles loading and
caching images from remote URLs. ImageLoader is a an
orchestrator for large numbers of ImageRequests, for example
when putting multiple thumbnails in a ListView.
 NetworkImageView—builds on ImageLoader and effectively
replaces ImageView for situations where your image is being
fetched over the network via URL. NetworkImageView also
manages canceling pending requests if the view is detached
from the hierarchy.
3.3 Use ImageRequest
 Create Singleton Class
 MainActivity.java
 Main_activity.xml
3.3.1 Create Singleton Class
3.3.1 Create Singleton Class
(Contd.)
3.3.2 main_activity.xml
3.3.3 MainActivity.java
Output
4. Using Request JSON
 Volley provides the following classes for JSON requests:
 JsonArrayRequest—A request for retrieving a JSONArray
response body at a given URL.
 JsonObjectRequest—A request for retrieving a JSONObject
response body at a given URL, allowing for an optional
JSONObject to be passed in as part of the request body.
Note: Both classes are based on the common base class
JsonRequest.
JSON Request
JsonObjectRequest request JsonObjectRequest(RequestMethod,
URL, null, new ResponseListener(), new ErrorListener());
Parameters passed into the constructor:
RequestMethod: (GET, POST, PUT, DELETE, etc.)
URL: String of the URL of the required object
JSONObject: An optional object posted with the request, null if there is no
object posted
ResponseListener: Response Listener, whose callback method will contain
the response
ErrorListener: A Response.ErrorListener whose callback method will
contain any problem with the request.
Example: Request JSON
 Create A New Class (MySingleton)
 MainActivity.java Class
 main_activity.xml Class
Creating a New Class
MainActivity.java
THANK YOU

More Related Content

What's hot

Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 
Express JS Rest API Tutorial
Express JS Rest API TutorialExpress JS Rest API Tutorial
Express JS Rest API TutorialSimplilearn
 
OAuth - Don’t Throw the Baby Out with the Bathwater
OAuth - Don’t Throw the Baby Out with the Bathwater OAuth - Don’t Throw the Baby Out with the Bathwater
OAuth - Don’t Throw the Baby Out with the Bathwater Apigee | Google Cloud
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in androidPrawesh Shrestha
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Devang Garach
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring   session 2 - La persistance au sein des applications JavaWorkshop spring   session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications JavaAntoine Rey
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & DevelopmentAshok Pundit
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding RESTNitin Pande
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootOmri Spector
 

What's hot (20)

Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
Express JS Rest API Tutorial
Express JS Rest API TutorialExpress JS Rest API Tutorial
Express JS Rest API Tutorial
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
OAuth - Don’t Throw the Baby Out with the Bathwater
OAuth - Don’t Throw the Baby Out with the Bathwater OAuth - Don’t Throw the Baby Out with the Bathwater
OAuth - Don’t Throw the Baby Out with the Bathwater
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Node.js
Node.jsNode.js
Node.js
 
Web api
Web apiWeb api
Web api
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring   session 2 - La persistance au sein des applications JavaWorkshop spring   session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
 

Similar to Volley in android

Transmitting network data using volley(14 09-16)
Transmitting network data using volley(14 09-16)Transmitting network data using volley(14 09-16)
Transmitting network data using volley(14 09-16)Sokngim Sa
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questionssurendray
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Droidcon Eastern Europe
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsEffie Arditi
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesRainer Stropek
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desaijinaldesailive
 
J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentjoearunraja2
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveDataAndroid MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveDataWaheed Nazir
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsSadayuki Furuhashi
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Roy de Kleijn
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxsalemsg
 
File Repository on GAE
File Repository on GAEFile Repository on GAE
File Repository on GAElynneblue
 

Similar to Volley in android (20)

Transmitting network data using volley(14 09-16)
Transmitting network data using volley(14 09-16)Transmitting network data using volley(14 09-16)
Transmitting network data using volley(14 09-16)
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
 
Struts
StrutsStruts
Struts
 
J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environment
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Modern android development
Modern android developmentModern android development
Modern android development
 
Master volley library
Master volley libraryMaster volley library
Master volley library
 
Skillwise Struts.x
Skillwise Struts.xSkillwise Struts.x
Skillwise Struts.x
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveDataAndroid MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Servlets
ServletsServlets
Servlets
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
 
File Repository on GAE
File Repository on GAEFile Repository on GAE
File Repository on GAE
 
Twet
TwetTwet
Twet
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Recently uploaded (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Volley in android

  • 1. Volley: Easy, Fast Networking for Android Prepared by: Himanshu Saini
  • 2. 1. Introduction To Volley 1. Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. 2. Volley is developed by Google & introduced during Google I/O 2013. 3. Volley is available through the AOSP or GitHub.
  • 3.  Using Volley In Your Project dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat- v7:24.0.0' compile 'com.android.volley:volley:1.0.0' }
  • 4. 2. Benefits of Volley  Automatic scheduling of network requests.  Multiple concurrent network connections.  Support for request prioritization.  Cancellation request API. You can cancel a single request, or you can set blocks or scopes of requests to cancel.  Ease of customization, for example, for retry and backoff.  Strong ordering that makes it easy to correctly populate your UI with data fetched asynchronously from the network.  Debugging and tracing tools.
  • 7. Worker Thread Main Thread doInBackground() Http Request Http Response  AsyncTask In Android
  • 8. Worker Thread Main Thread doInBackground() Http Request Http Response  AsyncTask In Android
  • 10. Main Thread Cache Thread Cache Dispatcher Network Thread Request Cash Miss Request Http Request Http Response Response Response Cache MemoryResponse Response
  • 11. Main Thread Cache Thread Cache Dispatcher Network Thread Request Cash Hit Cache Memory Response Request Response
  • 12. 2. Sending a Simple Request  Add the Internet permission  Use newRequestQueue  Send a RequestQueue  Cancel a Request
  • 13. 2.1 Add the Internet Permission  Add android.permission.INTERNET permission to app's manifest <uses-permission android:name="android.permission.INTERNET/>
  • 14. 2.2 Use newRequestQueue  Volley provides a convenience method Volley.newRequestQueue that sets up a RequestQueue for you, using default values, and starts the queue. // Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this);
  • 15. 2.3 Send a Request  To send a request, you simply construct one and add it to the RequestQueue object with add(StringRequest Object). // Add the request to the RequestQueue. queue.add(stringRequest);
  • 16. Processing Send a Request
  • 17. Example of RequestQueue and Send Request
  • 18. 2.4 Cancel a Request  To cancel a request, call cancelAll()on your Request object.  We can call cancel a request in onStop() method of An activtiy mRequestQueue.cancelAll(Object Tag); @Override protected void onStop () { super.onStop(); if (mRequestQueue != null) { mRequestQueue.cancelAll(TAG); } }
  • 19. Example  Define your tag and add it to your requests.
  • 20. Example (Contd.)  In your activity's onStop() method, cancel all requests that have this tag.
  • 21. 3. Making a Standard Request  Introduction to Standard Request  Request an Image  Use ImageRequest  Use ImageLoader and NetworkImageView  Request JSON
  • 22. 3.1 Introduction to Standard Request  StringRequest: Specify a URL and receive a raw string in response.  ImageRequest: Specify a URL and receive an image in response.  JsonObjectRequest and JsonArrayRequest (both subclasses of JsonRequest): Specify a URL and get a JSON object or array (respectively) in response.
  • 23. 3.2 Request an Image  Volley offers the following classes for requesting images. These classes layer on top of each other to offer different levels of support for processing images:  ImageRequest—a canned request for getting an image at a given URL and calling back with a decoded bitmap. It also provides convenience features like specifying a size to resize to.  ImageLoader—a helper class that handles loading and caching images from remote URLs. ImageLoader is a an orchestrator for large numbers of ImageRequests, for example when putting multiple thumbnails in a ListView.  NetworkImageView—builds on ImageLoader and effectively replaces ImageView for situations where your image is being fetched over the network via URL. NetworkImageView also manages canceling pending requests if the view is detached from the hierarchy.
  • 24. 3.3 Use ImageRequest  Create Singleton Class  MainActivity.java  Main_activity.xml
  • 26. 3.3.1 Create Singleton Class (Contd.)
  • 30. 4. Using Request JSON  Volley provides the following classes for JSON requests:  JsonArrayRequest—A request for retrieving a JSONArray response body at a given URL.  JsonObjectRequest—A request for retrieving a JSONObject response body at a given URL, allowing for an optional JSONObject to be passed in as part of the request body. Note: Both classes are based on the common base class JsonRequest.
  • 31. JSON Request JsonObjectRequest request JsonObjectRequest(RequestMethod, URL, null, new ResponseListener(), new ErrorListener()); Parameters passed into the constructor: RequestMethod: (GET, POST, PUT, DELETE, etc.) URL: String of the URL of the required object JSONObject: An optional object posted with the request, null if there is no object posted ResponseListener: Response Listener, whose callback method will contain the response ErrorListener: A Response.ErrorListener whose callback method will contain any problem with the request.
  • 32. Example: Request JSON  Create A New Class (MySingleton)  MainActivity.java Class  main_activity.xml Class
  • 33. Creating a New Class