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

Mobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android AppMobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android AppAbhilash Venkata
 
Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup Divyanshu
 
[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향Young-Ho Cho
 
Servlet vs Reactive Stacks in 5 Use Cases
Servlet vs Reactive Stacks in 5 Use CasesServlet vs Reactive Stacks in 5 Use Cases
Servlet vs Reactive Stacks in 5 Use CasesVMware Tanzu
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUDPrem Sanil
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriverAnuraj S.L
 
Android & iOS Automation Using Appium
Android & iOS Automation Using AppiumAndroid & iOS Automation Using Appium
Android & iOS Automation Using AppiumMindfire Solutions
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web APIBrad Genereaux
 
Spring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodeSpring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodedpTablo
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & DevelopmentAshok Pundit
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead ProgrammingNishant Mevawala
 

What's hot (20)

Mobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android AppMobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android App
 
Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup
 
GraphQL Security
GraphQL SecurityGraphQL Security
GraphQL Security
 
[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향
 
Servlet vs Reactive Stacks in 5 Use Cases
Servlet vs Reactive Stacks in 5 Use CasesServlet vs Reactive Stacks in 5 Use Cases
Servlet vs Reactive Stacks in 5 Use Cases
 
Web api
Web apiWeb api
Web api
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Android UI
Android UIAndroid UI
Android UI
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Core java
Core javaCore java
Core java
 
Android & iOS Automation Using Appium
Android & iOS Automation Using AppiumAndroid & iOS Automation Using Appium
Android & iOS Automation Using Appium
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Spring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodeSpring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCode
 
Android pentesting
Android pentestingAndroid pentesting
Android pentesting
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead Programming
 

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)
 
Android volley
Android volleyAndroid volley
Android volley
 
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
 

Recently uploaded

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
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
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
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
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
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
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
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
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
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
 

Recently uploaded (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
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
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
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...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
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 ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
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
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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
 

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