SlideShare a Scribd company logo
Android	
  Networking	
  and	
  	
  
  XML	
  Parsing	
  (SAX)	
  
        Jussi	
  Pohjolainen	
  
URLConnec@on	
  
1.  Obtain	
  a	
  new	
  HttpURLConnection	
  by	
  calling	
  
    URL.openConnection()	
  and	
  cas@ng	
  the	
  result	
  to	
  
    HGpURLConnec@on.	
  
2.  Prepare	
  the	
  request.	
  (URI)	
  
3.  Op@onally	
  upload	
  a	
  request	
  body	
  
4.  Read	
  the	
  response.	
  Response	
  headers	
  typically	
  include	
  metadata	
  
    such	
  as	
  the	
  response	
  body's	
  content	
  type	
  and	
  length,	
  modified	
  
    dates	
  and	
  session	
  cookies.	
  The	
  response	
  body	
  may	
  be	
  read	
  from	
  
    the	
  stream	
  returned	
  by	
  getInputStream().	
  	
  
5.  Disconnect.	
  Once	
  the	
  response	
  body	
  has	
  been	
  read,	
  the	
  
    HttpURLConnection	
  should	
  be	
  closed	
  by	
  calling	
  disconnect().	
  
    Disconnec@ng	
  frees	
  all	
  resources	
  held	
  by	
  a	
  connec@on.	
  
Fetching	
  URL	
  
URL url = new URL("http://www.somesite.fi");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

InputStream in = new BufferedInputStream(urlConnection.getInputStream());

String all = "";
int character;

while((character = stream.read()) != -1) {
    all += (char) character;
}

urlConnection.disconnect();
Asynchronous	
  HGp	
  
•  It’s	
  wise	
  to	
  fetch	
  data	
  in	
  separate	
  thread	
  
•  Standard	
  Java	
  threading	
  model	
  can	
  be	
  used,	
  
   but	
  touching	
  the	
  UI	
  thread	
  is	
  forbidden	
  in	
  
   Android	
  
•  To	
  update	
  UI	
  from	
  background	
  task,	
  you	
  need	
  
   Android	
  specific	
  classes	
  like	
  Handler.	
  
•  AsyncTask	
  is	
  a	
  class	
  that	
  wraps	
  threading	
  and	
  
   handling	
  UI	
  thread	
  in	
  the	
  same	
  class.	
  (Hold’s	
  
   Handler)	
  
AsyncTask	
  
AsyncTask	
  
Generic	
  Types	
  
•  The	
  three	
  types	
  used	
  by	
  an	
  asynchronous	
  task	
  
   are	
  the	
  following:	
  
    1.  Params,	
  the	
  type	
  of	
  the	
  parameters	
  sent	
  to	
  the	
  task	
  
        upon	
  execu@on.	
  
    2.  Progress,	
  the	
  type	
  of	
  the	
  progress	
  units	
  published	
  
        during	
  the	
  background	
  computa@on.	
  
    3.  Result,	
  the	
  type	
  of	
  the	
  result	
  of	
  the	
  background	
  
        computa@on.	
  
	
  	
  
private class MyTask extends
AsyncTask<Void, Void, Void> { ... }
	
  
Android Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
SAX	
  
•  Standard	
  Java	
  SAX	
  parsing	
  or	
  android	
  api	
  
   wrappers	
  
Standard	
  Java	
  SAX	
  
Standard	
  Java	
  SAX	
  

More Related Content

PDF
read and write program on c#
PDF
Android development training programme , Day 3
PDF
JS Fest 2019. Виктор Турский. 6 способов взломать твое JavaScript приложение
PPTX
Qt Translations
PDF
Responsive Web Site Design
PDF
Android Essential Tools
PDF
C# for Java Developers
PDF
Quick Intro to Android Development
read and write program on c#
Android development training programme , Day 3
JS Fest 2019. Виктор Турский. 6 способов взломать твое JavaScript приложение
Qt Translations
Responsive Web Site Design
Android Essential Tools
C# for Java Developers
Quick Intro to Android Development

Viewers also liked (15)

PDF
Android Security, Signing and Publishing
PDF
Building Web Services
PDF
Android Wi-Fi Manager and Bluetooth Connection
PDF
Android 2D Drawing and Animation Framework
PDF
00 introduction-mobile-programming-course.ppt
PDF
Android UI Development
PDF
Android Location and Maps
PDF
Android Threading
PDF
Android Data Persistence
PDF
Android Multimedia Support
PDF
Android Sensors
PDF
Android Telephony Manager and SMS
PDF
Short Intro to Android Fragments
PDF
Moved to Speakerdeck
PDF
Android Basic Components
Android Security, Signing and Publishing
Building Web Services
Android Wi-Fi Manager and Bluetooth Connection
Android 2D Drawing and Animation Framework
00 introduction-mobile-programming-course.ppt
Android UI Development
Android Location and Maps
Android Threading
Android Data Persistence
Android Multimedia Support
Android Sensors
Android Telephony Manager and SMS
Short Intro to Android Fragments
Moved to Speakerdeck
Android Basic Components
Ad

Similar to Android Http Connection and SAX Parsing (20)

PPTX
Android session-5-sajib
PDF
Session 9 Android Web Services - Part 2.pdf
PPT
Android - Thread, Handler and AsyncTask
PPT
Tech talk
PDF
PPTX
Php sql-android
PPTX
Android Application WebAPI Development Training
ODP
Android training day 5
PPTX
Mail OnLine Android Application at DroidCon - Turin - Italy
PDF
Connecting to-web-services-on-android-4577
ODP
Android App Development - 07 Threading
PDF
Programming Sideways: Asynchronous Techniques for Android
PDF
SAX - Android Development
PDF
[Android] Multiple Background Threads
PPTX
Android Connecting to internet Part 2
PDF
Connecting to Web Services on Android June 2 2010
PDF
Connecting to Web Services on Android
PDF
Asynchronous Programming in Android
PPTX
Java ME - 07 - Generic Connection Framework, HTTP and Sockets
PDF
Web Services and Android - OSSPAC 2009
Android session-5-sajib
Session 9 Android Web Services - Part 2.pdf
Android - Thread, Handler and AsyncTask
Tech talk
Php sql-android
Android Application WebAPI Development Training
Android training day 5
Mail OnLine Android Application at DroidCon - Turin - Italy
Connecting to-web-services-on-android-4577
Android App Development - 07 Threading
Programming Sideways: Asynchronous Techniques for Android
SAX - Android Development
[Android] Multiple Background Threads
Android Connecting to internet Part 2
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android
Asynchronous Programming in Android
Java ME - 07 - Generic Connection Framework, HTTP and Sockets
Web Services and Android - OSSPAC 2009
Ad

More from Jussi Pohjolainen (20)

PDF
Java Web Services
PDF
Box2D and libGDX
PDF
libGDX: Screens, Fonts and Preferences
PDF
libGDX: Tiled Maps
PDF
libGDX: User Input and Frame by Frame Animation
PDF
Intro to Building Android Games using libGDX
PDF
Advanced JavaScript Development
PDF
Introduction to JavaScript
PDF
Introduction to AngularJS
PDF
libGDX: Scene2D
PDF
libGDX: Simple Frame Animation
PDF
libGDX: Simple Frame Animation
PDF
libGDX: User Input
PDF
Implementing a Simple Game using libGDX
PDF
Building Android games using LibGDX
PDF
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
PDF
Creating Games for Asha - platform
PDF
Intro to Asha UI
PDF
Intro to Java ME and Asha Platform
PDF
Intro to PhoneGap
Java Web Services
Box2D and libGDX
libGDX: Screens, Fonts and Preferences
libGDX: Tiled Maps
libGDX: User Input and Frame by Frame Animation
Intro to Building Android Games using libGDX
Advanced JavaScript Development
Introduction to JavaScript
Introduction to AngularJS
libGDX: Scene2D
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
libGDX: User Input
Implementing a Simple Game using libGDX
Building Android games using LibGDX
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Games for Asha - platform
Intro to Asha UI
Intro to Java ME and Asha Platform
Intro to PhoneGap

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
A Presentation on Artificial Intelligence
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Modernizing your data center with Dell and AMD
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
A Presentation on Artificial Intelligence
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Weekly Chronicles - August'25 Week I
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Android Http Connection and SAX Parsing

  • 1. Android  Networking  and     XML  Parsing  (SAX)   Jussi  Pohjolainen  
  • 2. URLConnec@on   1.  Obtain  a  new  HttpURLConnection  by  calling   URL.openConnection()  and  cas@ng  the  result  to   HGpURLConnec@on.   2.  Prepare  the  request.  (URI)   3.  Op@onally  upload  a  request  body   4.  Read  the  response.  Response  headers  typically  include  metadata   such  as  the  response  body's  content  type  and  length,  modified   dates  and  session  cookies.  The  response  body  may  be  read  from   the  stream  returned  by  getInputStream().     5.  Disconnect.  Once  the  response  body  has  been  read,  the   HttpURLConnection  should  be  closed  by  calling  disconnect().   Disconnec@ng  frees  all  resources  held  by  a  connec@on.  
  • 3. Fetching  URL   URL url = new URL("http://www.somesite.fi"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); String all = ""; int character; while((character = stream.read()) != -1) { all += (char) character; } urlConnection.disconnect();
  • 4. Asynchronous  HGp   •  It’s  wise  to  fetch  data  in  separate  thread   •  Standard  Java  threading  model  can  be  used,   but  touching  the  UI  thread  is  forbidden  in   Android   •  To  update  UI  from  background  task,  you  need   Android  specific  classes  like  Handler.   •  AsyncTask  is  a  class  that  wraps  threading  and   handling  UI  thread  in  the  same  class.  (Hold’s   Handler)  
  • 7. Generic  Types   •  The  three  types  used  by  an  asynchronous  task   are  the  following:   1.  Params,  the  type  of  the  parameters  sent  to  the  task   upon  execu@on.   2.  Progress,  the  type  of  the  progress  units  published   during  the  background  computa@on.   3.  Result,  the  type  of  the  result  of  the  background   computa@on.       private class MyTask extends AsyncTask<Void, Void, Void> { ... }  
  • 10. SAX   •  Standard  Java  SAX  parsing  or  android  api   wrappers