SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
25/07/16 Presentation 1
Android HTTP library
Surviving with Android
Presentation 225/07/16
What is it?
When we develop an Android app, usually we have to connect to a remote
server to get information. The connection usually is based on HTTP protocol
because it provides a simple mechanism to transport information. Moreover,
almost all platforms provide a set of API based on HTTP and it is very common
the scenario where an Android app needs to integrate with one of these
platforms. For these reasons, it is important to know how to choose the best
Android HTTP library. The best choice, of course, depends on the requirements
of our Android app, so we can provide some hints that help you to select the
best Android HTTP library according to our needs.
Presentation 325/07/16
Android HTTP Library:
The Android HTTP library is based on HttpUrlConnection. This Android HTTP
library supports HTTP and HTTPS protocol and it is the basic class to use when
handling HTTP connection. Before Android 6.0, there was another library
shipped with Android SDK, called Android Apache HTTP. To use it:
android {
    useLibrary 'org.apache.http.legacy'
}
Presentation 425/07/16
Android HTTP Library:
The Android HTTP library is based on HttpUrlConnection. This Android HTTP
library supports HTTP and HTTPS protocol and it is the basic class to use when
handling HTTP connection. Before Android 6.0, there was another library
shipped with Android SDK, called Android Apache HTTP. To use it:
android {
    useLibrary 'org.apache.http.legacy'
}
Presentation 525/07/16
HttpUrlConnection
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) (new URL(url)).openConnection();
connection.setRequestMethod("GET"); // or post
connection.connect();
InputStream is = connection.getInputStream();
}
Even if it is simple to use there is a drawback: we don’t have to make HTTP calls in UI
thread. For this reason, the piece of code above must be wrapped in a different thread.
Usually, the class used with HttpUrlConnection is the AsyncTask.
Presentation 625/07/16
Android HTTP Alternatives
Third-part libraries have these advantages:
● Efficiency
● Parallel requests
● Caching system
● Non-blocking UI thread
● HTTP/2 support
At level of HTTP handling there are two main libraries:
● Volley
● OkHTTP
Presentation 725/07/16
Android Volley
Android Volley is library made by Google and offers very
interesting features, as stated in its home page:
● Automatic scheduling of network requests
● Multiple concurrent network connections.
● Support for request prioritization
● Cancellation request API
Presentation 825/07/16
Android Volley: How to..
RequestQueue queue = Volley.newRequestQueue(ctx);
StringRequest req = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String data) {}
},
new Response.ErrorListener() {
@Override
OnError(...) {}
} );
queue.add(req);
Presentation 925/07/16
OkHTTP
OkHTTP is another interesting libraries to handle HTTP connections.
The main advantages provided by OkHTTP are:
●
HTTP/2 support
●
Connection pooling
●
Response caching
Presentation 1025/07/16
OkHTTP
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
// Handle error
}
@Override
public void onResponse(Response response) throws IOException
{
//handle response
}
});
Presentation 1125/07/16
Find more...
To find more information please visit
Android HTTP library: Handle HTTP, JSON, Images
Follow me @survivingwithan
25/07/16 Presentation 12
Thank you

Weitere ähnliche Inhalte

Andere mochten auch

Prettig kerstfeest en een gelukkig Nieuwjaar!
Prettig kerstfeest en een gelukkig Nieuwjaar!Prettig kerstfeest en een gelukkig Nieuwjaar!
Prettig kerstfeest en een gelukkig Nieuwjaar!
dieterj
 
NOORA AL AZZONE CV
NOORA AL AZZONE CVNOORA AL AZZONE CV
NOORA AL AZZONE CV
noora azzone
 

Andere mochten auch (16)

Restful Services
Restful ServicesRestful Services
Restful Services
 
Lateral thinking by edward de bono
Lateral thinking by edward de bono Lateral thinking by edward de bono
Lateral thinking by edward de bono
 
Film pitch
Film pitchFilm pitch
Film pitch
 
Trabalhando com TI
Trabalhando com TITrabalhando com TI
Trabalhando com TI
 
Sanad Jamal CV
Sanad Jamal CVSanad Jamal CV
Sanad Jamal CV
 
Artes_Events
Artes_EventsArtes_Events
Artes_Events
 
Prettig kerstfeest en een gelukkig Nieuwjaar!
Prettig kerstfeest en een gelukkig Nieuwjaar!Prettig kerstfeest en een gelukkig Nieuwjaar!
Prettig kerstfeest en een gelukkig Nieuwjaar!
 
NOORA AL AZZONE CV
NOORA AL AZZONE CVNOORA AL AZZONE CV
NOORA AL AZZONE CV
 
Gae managed vm introduction
Gae managed vm introductionGae managed vm introduction
Gae managed vm introduction
 
Nabil F. Fayed Business Profile V.2
Nabil F. Fayed Business Profile V.2Nabil F. Fayed Business Profile V.2
Nabil F. Fayed Business Profile V.2
 
O preço do discipulado
O preço do discipuladoO preço do discipulado
O preço do discipulado
 
Práticas Administrativas
Práticas AdministrativasPráticas Administrativas
Práticas Administrativas
 
Django oscar introduction
Django oscar introductionDjango oscar introduction
Django oscar introduction
 
Android: a full-stack to consume a REST API
Android: a full-stack to consume a REST APIAndroid: a full-stack to consume a REST API
Android: a full-stack to consume a REST API
 
Práticas de Recursos Humanos - Aula 1 a 10
Práticas de Recursos Humanos - Aula 1 a 10Práticas de Recursos Humanos - Aula 1 a 10
Práticas de Recursos Humanos - Aula 1 a 10
 
O poder régio
O poder régioO poder régio
O poder régio
 

Ähnlich wie Android http library

Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
raviIITRoorkee
 

Ähnlich wie Android http library (20)

Introduction to Apigility
Introduction to ApigilityIntroduction to Apigility
Introduction to Apigility
 
Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)
 
Mobile web development
Mobile web developmentMobile web development
Mobile web development
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Web Server and how we can design app in C#
Web Server and how we can design app  in C#Web Server and how we can design app  in C#
Web Server and how we can design app in C#
 
Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
 
Android httpclient
Android httpclientAndroid httpclient
Android httpclient
 
Session 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdfSession 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdf
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
RESTful application with Drupal 8
RESTful application with Drupal 8RESTful application with Drupal 8
RESTful application with Drupal 8
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
Android application architecture
Android application architectureAndroid application architecture
Android application architecture
 
Application integration with the W3C Linked Data standards
Application integration with the W3C Linked Data standardsApplication integration with the W3C Linked Data standards
Application integration with the W3C Linked Data standards
 
Abhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_techAbhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_tech
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST API
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
 
Spider Course Day 1
Spider Course Day 1Spider Course Day 1
Spider Course Day 1
 

Kürzlich hochgeladen

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Cara Menggugurkan Kandungan 087776558899
 

Kürzlich hochgeladen (6)

Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
 

Android http library

  • 1. 25/07/16 Presentation 1 Android HTTP library Surviving with Android
  • 2. Presentation 225/07/16 What is it? When we develop an Android app, usually we have to connect to a remote server to get information. The connection usually is based on HTTP protocol because it provides a simple mechanism to transport information. Moreover, almost all platforms provide a set of API based on HTTP and it is very common the scenario where an Android app needs to integrate with one of these platforms. For these reasons, it is important to know how to choose the best Android HTTP library. The best choice, of course, depends on the requirements of our Android app, so we can provide some hints that help you to select the best Android HTTP library according to our needs.
  • 3. Presentation 325/07/16 Android HTTP Library: The Android HTTP library is based on HttpUrlConnection. This Android HTTP library supports HTTP and HTTPS protocol and it is the basic class to use when handling HTTP connection. Before Android 6.0, there was another library shipped with Android SDK, called Android Apache HTTP. To use it: android {     useLibrary 'org.apache.http.legacy' }
  • 4. Presentation 425/07/16 Android HTTP Library: The Android HTTP library is based on HttpUrlConnection. This Android HTTP library supports HTTP and HTTPS protocol and it is the basic class to use when handling HTTP connection. Before Android 6.0, there was another library shipped with Android SDK, called Android Apache HTTP. To use it: android {     useLibrary 'org.apache.http.legacy' }
  • 5. Presentation 525/07/16 HttpUrlConnection HttpURLConnection connection = null; try { connection = (HttpURLConnection) (new URL(url)).openConnection(); connection.setRequestMethod("GET"); // or post connection.connect(); InputStream is = connection.getInputStream(); } Even if it is simple to use there is a drawback: we don’t have to make HTTP calls in UI thread. For this reason, the piece of code above must be wrapped in a different thread. Usually, the class used with HttpUrlConnection is the AsyncTask.
  • 6. Presentation 625/07/16 Android HTTP Alternatives Third-part libraries have these advantages: ● Efficiency ● Parallel requests ● Caching system ● Non-blocking UI thread ● HTTP/2 support At level of HTTP handling there are two main libraries: ● Volley ● OkHTTP
  • 7. Presentation 725/07/16 Android Volley Android Volley is library made by Google and offers very interesting features, as stated in its home page: ● Automatic scheduling of network requests ● Multiple concurrent network connections. ● Support for request prioritization ● Cancellation request API
  • 8. Presentation 825/07/16 Android Volley: How to.. RequestQueue queue = Volley.newRequestQueue(ctx); StringRequest req = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String data) {} }, new Response.ErrorListener() { @Override OnError(...) {} } ); queue.add(req);
  • 9. Presentation 925/07/16 OkHTTP OkHTTP is another interesting libraries to handle HTTP connections. The main advantages provided by OkHTTP are: ● HTTP/2 support ● Connection pooling ● Response caching
  • 10. Presentation 1025/07/16 OkHTTP OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url(url).build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { // Handle error } @Override public void onResponse(Response response) throws IOException { //handle response } });
  • 11. Presentation 1125/07/16 Find more... To find more information please visit Android HTTP library: Handle HTTP, JSON, Images Follow me @survivingwithan