SlideShare a Scribd company logo
Native Android Development with Spring

Roy Clarkson
Spring Mobile Projects Lead
SpringSource, a division of VMware
@royclarkson
@springandroid




                                     © 2010 SpringSource, A division of VMware. All rights reserved
                                       2012
Introduction

§ What are the purposes of the Spring for Android
 and Spring Mobile projects?

 • Spring for Android provides support for building native
  Android applications utilizing Spring technologies, where
  applicable.

 • In contrast, Spring Mobile provides support for building
  mobile web applications.




                             CONFIDENTIAL
                                                              2
Spring for Android
 • Android Overview
 • Define the Problem
 • Review of REST
 • Basic Rest Template Example
 • Rest Template Overview
 • Maven Can Help
 • Showcase and Demos
 • Questions



                        CONFIDENTIAL
                                       3
Android Adoption

§ Year-on-year growth rate of more than 250%
§ 850,000 new Android devices are activated each day
§ Over 300 million devices around the world
§ Over 450,000 apps available in Google Play
§ Over 1 billion app downloads per month




 http://googlemobile.blogspot.com/2012/02/androidmobile-world-congress-its-all.html

                                      CONFIDENTIAL
                                                                                      4
Android Fragmentation

§ Current Distribution
 • Gingerbread 62%
 • Froyo 25.3%
 • Eclair 6.6%
 • Honeycomb 3.3%
 • Ice Cream
   Sandwich 1.6%




 http://developer.android.com/resources/dashboard/platform-versions.html

                                 CONFIDENTIAL
                                                                           5
Android is Familiar




            Applications are written in Java!
                      (well, sort of)




                         CONFIDENTIAL
                                                6
But not that Familiar...


§ Class Files
 • Android apps are compiled to class files.

§ DEX Format
 • Classes are compiled into the Dalvik Executable (DEX) format.
 • DEX format is required to run on the Dalvik Virtual Machine.

§ Dalvik VM
 • Not a true Java VM, because it does not operate on Java byte code.
 • Based on a subset of the Apache Harmony project.
 • Many of the classes from Java SE are available, but not all.


                                CONFIDENTIAL
                                                                        7
Isolation of an App


§ Unique Linux User ID
   • Android OS assigns each app a unique Linux user ID.

§ Process Isolation
   • Within the VM, each app runs in its own Linux process.

§ Managed Lifecycle
   • The system manages the starting and stopping.




                            CONFIDENTIAL
                                                              8
Components of an Android App

§ Activities - An activity represents a single screen with a
 user interface.

§ Services - A service is a component that runs in the
 background to perform long-running operations or to
 perform work for remote processes.

§ Content Providers - A content provider manages a
 shared set of application data.

§ Broadcast Receivers - A broadcast receiver is a
 component that responds to system-wide broadcast
 announcements.

     http://developer.android.com/guide/topics/fundamentals.html

                                CONFIDENTIAL
                                                                   9
Android Manifest


§ contains the permissions requested by the app
§ Lists all of the components of an app

<uses-sdk android:minSdkVersion="10" />
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".HelloAndroidActivity"
        android:label="@string/app_name" >
        <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>




                                   CONFIDENTIAL
                                                                            10
A simple Activity



package org.springsource;

import android.app.Activity;
import android.os.Bundle;

public class HelloAndroidActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}




                               CONFIDENTIAL
                                                        11
STS and the ADT Plugin for Eclipse



                      HelloAndroid Demo




     http://www.springsource.org/springsource-tool-suite-download

           http://developer.android.com/sdk/eclipse-adt.html

                                CONFIDENTIAL
                                                                    12
How can Maven help?
§ Android4Maven
 • This project compiles android.jar from source and pulls out
   source and resource files to replicate android.jar in the SDK
 • http://sourceforge.net/projects/android4maven/

§ Maven Android SDK Deployer
 • If you need to use Google maps, then you have to go this
   route
 • https://github.com/mosabua/maven-android-sdk-deployer

§ Android Maven Plugin
 • Provides support for Maven dependency management within
   Android projects
 • http://code.google.com/p/maven-android-plugin/

                              CONFIDENTIAL
                                                                   13
Android Maven Plugin Configuration


<packaging>apk</packaging>



<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>3.1.1</version>
    <configuration>
         <sdk>
             <platform>${android-platform}</platform>
         </sdk>
         <deleteConflictingFiles>true</deleteConflictingFiles>
         <undeployBeforeDeploy>true</undeployBeforeDeploy>
    </configuration>
    <extensions>true</extensions>
</plugin>



https://repository.sonatype.org/index.html#nexus-search;quick~com.google.android

                                    CONFIDENTIAL
                                                                               14
Maven Commands

Build your Android App
$ mvn clean install


Start the Emulator
$ mvn android:emulator-start


Deploy the app to the emulator
$ mvn android:deploy


Run the app
$ mvn android:run




  http://maven-android-plugin-m2site.googlecode.com/svn/plugin-info.html

                                 CONFIDENTIAL
                                                                           15
Maven Demo




   CONFIDENTIAL
                  16
m2eclipse Support


§ Android Configurator for M2E Maven Integration for Eclipse
 • An Eclipse plugin that adds support for integrating m2eclipse, Android
   Developer Tools, and the Android Maven Plugin
 • http://rgladwell.github.com/m2e-android/

§ Maven Android archetypes
 • This project provides several Maven archetypes for Android. These
   archetypes allow you to quickly bootstrap a Maven project to develop an
   android application.
 • https://github.com/akquinet/android-archetypes




                                  CONFIDENTIAL
                                                                            17
This sounds too good!




                        @rgladwell

                          CONFIDENTIAL
                                         18
Spring for Android




       CONFIDENTIAL
                      19
What problem are we trying to solve?


§ Concerns
 • REST has become a popular choice for architecting both public
   and private web services
 • The Android runtime provides HTTP clients capable of making
   HTTP connections and requests, but it does not have a fully
   featured REST client

§ Spring for Android Solution
 • The goal of Spring for Android Rest Template is to provide an
  easy to use, and functional REST client that supports marshaling
  objects from XML and JSON.




                               CONFIDENTIAL
                                                                   20
REST

§ Origin
 • The term Representational State Transfer was introduced and
   defined in 2000 by Roy Fielding in his doctoral dissertation.

§ His paper suggests these four design principles:
 • Use HTTP methods explicitly.
   • POST, GET, PUT, DELETE
   • CRUD operations can be mapped to these existing methods
 • Be stateless.
   • State dependencies limit or restrict scalability
 • Expose directory structure-like URIs.
   • URI’s should be easily understood
 • Transfer XML, JavaScript Object Notation (JSON), or both.
   • Use XML or JSON to represent data objects or attributes


                                CONFIDENTIAL
                                                                   21
Basic Rest Template Example


§ Google search example
RestTemplate restTemplate = new RestTemplate();
String url =
"https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}";
String result = restTemplate.getForObject(url, String.class, "SpringSource");




§ Multiple parameters example
RestTemplate restTemplate = new RestTemplate();
String url = "http://example.com/hotels/{hotel}/bookings/{booking}";
String result = restTemplate.getForObject(url, String.class, "42", “21”);




                                    CONFIDENTIAL
                                                                                22
Google Search Demo




       CONFIDENTIAL
                      23
Spring for Android Rest Template


§ Based on SpringFramework
 • Originated as a fork of RestTemplate from SpringFramework.
 • Modifications were made to support Android.

§ RestTemplate class is the heart of the library
 • Entry points for the six main HTTP methods
   • DELETE - delete(...)
   • GET - getForObject(...)
   • HEAD - headForHeaders(...)
   • OPTIONS - optionsForAllow(...)
   • POST - postForLocation(...)
   • PUT - put(...)
   • any HTTP operation - exchange(...) and execute(...)

                                 CONFIDENTIAL
                                                                24
HTTP Clients


§ SimpleClientHttpRequestFactory
 • Delegates to the standard J2SE facilities

§ HttpComponentsClientHttpRequestFactory
 • Delegates to the native HttpComponents HttpClient

§ CommonsClientHttpRequestFactory (deprecated)
 • Delegates to the Commons HttpClient which is not native to Android




                                CONFIDENTIAL
                                                                    25
Message Converters


§ MappingJacksonHttpMessageConverter
 • object to JSON marshaling supported via the Jackson JSON Processor


§ SimpleXmlHttpMessageConverter
 • object to XML marshaling supported via the Simple XML Serializer


§ SyndFeedHttpMessageConverter
 • RSS and Atom feeds supported via the Android ROME Feed Reader




                                CONFIDENTIAL
                                                                      26
Spring for Android Showcase

§ Examples
 • HTTP GET
   • JSON
   • XML
 • HTTP GET with Parameters
   • JSON
   • XML
 • HTTP POST
   •   String
   •   JSON
   •   XML
   •   MultiValueMap
 • RSS
 • ATOM


                              CONFIDENTIAL
                                             27
Rest Template Demos




       CONFIDENTIAL
                      28
Spring Social on Android


§ What is Spring Social?
 • Spring Social is an extension of the Spring Framework that allows you to
   connect your applications with Software-as-a-Service (SaaS) providers such as
   Facebook and Twitter.


§ How does it relate to Spring for Android?
 • Utilizes RestTemplate to make RESTful requests to providers.

§ How can Spring for Android help?
 • Auth library in Spring for Android provides a SQLiteConnectionRepository for
   use with Spring Social.




                                     CONFIDENTIAL
                                                                                  29
Additional Resources

§ Slides:
  • http://portal.sliderocket.com/vmware/Native-Android-Development-with-Spring
§ Project Home:
  • http://www.springsource.org/spring-android
§ Sample Code:
  • https://github.com/SpringSource/spring-android-samples
§ Webinar:
  • http://www.springsource.org/node/3505
§ Blog Posts:
  • http://blog.springsource.com/author/rclarkson/




                                      CONFIDENTIAL
                                                                                  30

More Related Content

PDF
Native Android Development Practices
PPT
Making the Mobile Web Native with PhoneGap
PDF
Extending Spring MVC with Spring Mobile and JavaScript
PDF
Mobile Web Development with HTML5
PDF
Spring Projects Infrastructure
PPTX
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
PPTX
App forum2015 London - Building RhoMobile Applications with Ionic
PPTX
Intro to Ionic for Building Hybrid Mobile Applications
Native Android Development Practices
Making the Mobile Web Native with PhoneGap
Extending Spring MVC with Spring Mobile and JavaScript
Mobile Web Development with HTML5
Spring Projects Infrastructure
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
App forum2015 London - Building RhoMobile Applications with Ionic
Intro to Ionic for Building Hybrid Mobile Applications

What's hot (20)

PDF
Ionic - Revolutionizing Hybrid Mobile Application Development
PPTX
Developing Hybrid Applications with IONIC
PPTX
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015
PPTX
Selendroid - Selenium for Android
PDF
Intro to PhoneGap
PDF
Ionic framework one day training
PPTX
Ionic Mobile Applications - Hybrid Mobile Applications Without Compromises
PDF
Lesson 1. Create project Sunshine
PDF
Ionic Framework: Let's build amazing apps. No Excuses!
PDF
Hybrid app development with ionic
PDF
[Lighting Talk] - Ionic 2 Tour
PDF
React Nativeアプリをリリースし続けるために、最初に行う8つの取り組み
PPTX
Hybrid Mobile Applications
KEY
jQuery Conference Boston 2011 CouchApps
PDF
Being Epic: Best Practices for Android Development
PPTX
Introduction to Apache Cordova (Phonegap)
PDF
Cross-platform development frameworks
PDF
Experiences building apps with React Native @DomCode 2016
PPTX
Appcelerator Titanium Intro
PDF
GR8Conf 2009. The Grails Plugin System by Graeme Rocher
Ionic - Revolutionizing Hybrid Mobile Application Development
Developing Hybrid Applications with IONIC
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015
Selendroid - Selenium for Android
Intro to PhoneGap
Ionic framework one day training
Ionic Mobile Applications - Hybrid Mobile Applications Without Compromises
Lesson 1. Create project Sunshine
Ionic Framework: Let's build amazing apps. No Excuses!
Hybrid app development with ionic
[Lighting Talk] - Ionic 2 Tour
React Nativeアプリをリリースし続けるために、最初に行う8つの取り組み
Hybrid Mobile Applications
jQuery Conference Boston 2011 CouchApps
Being Epic: Best Practices for Android Development
Introduction to Apache Cordova (Phonegap)
Cross-platform development frameworks
Experiences building apps with React Native @DomCode 2016
Appcelerator Titanium Intro
GR8Conf 2009. The Grails Plugin System by Graeme Rocher
Ad

Similar to Native Android Development with Spring (20)

PDF
Androidoscon20080721 1216843094441821-9
PDF
Androidoscon20080721 1216843094441821-9
PPTX
From Containerization to Modularity
PPT
Android Application Development Using Java
PPT
Android - Anroid Pproject
PDF
Android application development
PDF
Android dev o_auth
PPT
Android
PPTX
Mobile web development
PPT
Oracle mcs overview 1029
PDF
Domo Arigato Mr. Roboto - Open Source Bridge 2009
KEY
Android Workshop
PPT
Synapseindia android apps application
PDF
Introduction to android
PPT
Android development orientation for starters v4 seminar
PPTX
Intro to android (gdays)
PPTX
Ii 1300-java essentials for android
PDF
Android Jump Start
PDF
iOS App Using cordova
PPTX
Developing for Android-Types of Android Application
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9
From Containerization to Modularity
Android Application Development Using Java
Android - Anroid Pproject
Android application development
Android dev o_auth
Android
Mobile web development
Oracle mcs overview 1029
Domo Arigato Mr. Roboto - Open Source Bridge 2009
Android Workshop
Synapseindia android apps application
Introduction to android
Android development orientation for starters v4 seminar
Intro to android (gdays)
Ii 1300-java essentials for android
Android Jump Start
iOS App Using cordova
Developing for Android-Types of Android Application
Ad

Recently uploaded (20)

PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation theory and applications.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
The AUB Centre for AI in Media Proposal.docx
Chapter 3 Spatial Domain Image Processing.pdf
A Presentation on Artificial Intelligence
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Spectral efficient network and resource selection model in 5G networks
Understanding_Digital_Forensics_Presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
NewMind AI Monthly Chronicles - July 2025

Native Android Development with Spring

  • 1. Native Android Development with Spring Roy Clarkson Spring Mobile Projects Lead SpringSource, a division of VMware @royclarkson @springandroid © 2010 SpringSource, A division of VMware. All rights reserved 2012
  • 2. Introduction § What are the purposes of the Spring for Android and Spring Mobile projects? • Spring for Android provides support for building native Android applications utilizing Spring technologies, where applicable. • In contrast, Spring Mobile provides support for building mobile web applications. CONFIDENTIAL 2
  • 3. Spring for Android • Android Overview • Define the Problem • Review of REST • Basic Rest Template Example • Rest Template Overview • Maven Can Help • Showcase and Demos • Questions CONFIDENTIAL 3
  • 4. Android Adoption § Year-on-year growth rate of more than 250% § 850,000 new Android devices are activated each day § Over 300 million devices around the world § Over 450,000 apps available in Google Play § Over 1 billion app downloads per month http://googlemobile.blogspot.com/2012/02/androidmobile-world-congress-its-all.html CONFIDENTIAL 4
  • 5. Android Fragmentation § Current Distribution • Gingerbread 62% • Froyo 25.3% • Eclair 6.6% • Honeycomb 3.3% • Ice Cream Sandwich 1.6% http://developer.android.com/resources/dashboard/platform-versions.html CONFIDENTIAL 5
  • 6. Android is Familiar Applications are written in Java! (well, sort of) CONFIDENTIAL 6
  • 7. But not that Familiar... § Class Files • Android apps are compiled to class files. § DEX Format • Classes are compiled into the Dalvik Executable (DEX) format. • DEX format is required to run on the Dalvik Virtual Machine. § Dalvik VM • Not a true Java VM, because it does not operate on Java byte code. • Based on a subset of the Apache Harmony project. • Many of the classes from Java SE are available, but not all. CONFIDENTIAL 7
  • 8. Isolation of an App § Unique Linux User ID • Android OS assigns each app a unique Linux user ID. § Process Isolation • Within the VM, each app runs in its own Linux process. § Managed Lifecycle • The system manages the starting and stopping. CONFIDENTIAL 8
  • 9. Components of an Android App § Activities - An activity represents a single screen with a user interface. § Services - A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. § Content Providers - A content provider manages a shared set of application data. § Broadcast Receivers - A broadcast receiver is a component that responds to system-wide broadcast announcements. http://developer.android.com/guide/topics/fundamentals.html CONFIDENTIAL 9
  • 10. Android Manifest § contains the permissions requested by the app § Lists all of the components of an app <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".HelloAndroidActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> CONFIDENTIAL 10
  • 11. A simple Activity package org.springsource; import android.app.Activity; import android.os.Bundle; public class HelloAndroidActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } CONFIDENTIAL 11
  • 12. STS and the ADT Plugin for Eclipse HelloAndroid Demo http://www.springsource.org/springsource-tool-suite-download http://developer.android.com/sdk/eclipse-adt.html CONFIDENTIAL 12
  • 13. How can Maven help? § Android4Maven • This project compiles android.jar from source and pulls out source and resource files to replicate android.jar in the SDK • http://sourceforge.net/projects/android4maven/ § Maven Android SDK Deployer • If you need to use Google maps, then you have to go this route • https://github.com/mosabua/maven-android-sdk-deployer § Android Maven Plugin • Provides support for Maven dependency management within Android projects • http://code.google.com/p/maven-android-plugin/ CONFIDENTIAL 13
  • 14. Android Maven Plugin Configuration <packaging>apk</packaging> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <version>3.1.1</version> <configuration> <sdk> <platform>${android-platform}</platform> </sdk> <deleteConflictingFiles>true</deleteConflictingFiles> <undeployBeforeDeploy>true</undeployBeforeDeploy> </configuration> <extensions>true</extensions> </plugin> https://repository.sonatype.org/index.html#nexus-search;quick~com.google.android CONFIDENTIAL 14
  • 15. Maven Commands Build your Android App $ mvn clean install Start the Emulator $ mvn android:emulator-start Deploy the app to the emulator $ mvn android:deploy Run the app $ mvn android:run http://maven-android-plugin-m2site.googlecode.com/svn/plugin-info.html CONFIDENTIAL 15
  • 16. Maven Demo CONFIDENTIAL 16
  • 17. m2eclipse Support § Android Configurator for M2E Maven Integration for Eclipse • An Eclipse plugin that adds support for integrating m2eclipse, Android Developer Tools, and the Android Maven Plugin • http://rgladwell.github.com/m2e-android/ § Maven Android archetypes • This project provides several Maven archetypes for Android. These archetypes allow you to quickly bootstrap a Maven project to develop an android application. • https://github.com/akquinet/android-archetypes CONFIDENTIAL 17
  • 18. This sounds too good! @rgladwell CONFIDENTIAL 18
  • 19. Spring for Android CONFIDENTIAL 19
  • 20. What problem are we trying to solve? § Concerns • REST has become a popular choice for architecting both public and private web services • The Android runtime provides HTTP clients capable of making HTTP connections and requests, but it does not have a fully featured REST client § Spring for Android Solution • The goal of Spring for Android Rest Template is to provide an easy to use, and functional REST client that supports marshaling objects from XML and JSON. CONFIDENTIAL 20
  • 21. REST § Origin • The term Representational State Transfer was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. § His paper suggests these four design principles: • Use HTTP methods explicitly. • POST, GET, PUT, DELETE • CRUD operations can be mapped to these existing methods • Be stateless. • State dependencies limit or restrict scalability • Expose directory structure-like URIs. • URI’s should be easily understood • Transfer XML, JavaScript Object Notation (JSON), or both. • Use XML or JSON to represent data objects or attributes CONFIDENTIAL 21
  • 22. Basic Rest Template Example § Google search example RestTemplate restTemplate = new RestTemplate(); String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}"; String result = restTemplate.getForObject(url, String.class, "SpringSource"); § Multiple parameters example RestTemplate restTemplate = new RestTemplate(); String url = "http://example.com/hotels/{hotel}/bookings/{booking}"; String result = restTemplate.getForObject(url, String.class, "42", “21”); CONFIDENTIAL 22
  • 23. Google Search Demo CONFIDENTIAL 23
  • 24. Spring for Android Rest Template § Based on SpringFramework • Originated as a fork of RestTemplate from SpringFramework. • Modifications were made to support Android. § RestTemplate class is the heart of the library • Entry points for the six main HTTP methods • DELETE - delete(...) • GET - getForObject(...) • HEAD - headForHeaders(...) • OPTIONS - optionsForAllow(...) • POST - postForLocation(...) • PUT - put(...) • any HTTP operation - exchange(...) and execute(...) CONFIDENTIAL 24
  • 25. HTTP Clients § SimpleClientHttpRequestFactory • Delegates to the standard J2SE facilities § HttpComponentsClientHttpRequestFactory • Delegates to the native HttpComponents HttpClient § CommonsClientHttpRequestFactory (deprecated) • Delegates to the Commons HttpClient which is not native to Android CONFIDENTIAL 25
  • 26. Message Converters § MappingJacksonHttpMessageConverter • object to JSON marshaling supported via the Jackson JSON Processor § SimpleXmlHttpMessageConverter • object to XML marshaling supported via the Simple XML Serializer § SyndFeedHttpMessageConverter • RSS and Atom feeds supported via the Android ROME Feed Reader CONFIDENTIAL 26
  • 27. Spring for Android Showcase § Examples • HTTP GET • JSON • XML • HTTP GET with Parameters • JSON • XML • HTTP POST • String • JSON • XML • MultiValueMap • RSS • ATOM CONFIDENTIAL 27
  • 28. Rest Template Demos CONFIDENTIAL 28
  • 29. Spring Social on Android § What is Spring Social? • Spring Social is an extension of the Spring Framework that allows you to connect your applications with Software-as-a-Service (SaaS) providers such as Facebook and Twitter. § How does it relate to Spring for Android? • Utilizes RestTemplate to make RESTful requests to providers. § How can Spring for Android help? • Auth library in Spring for Android provides a SQLiteConnectionRepository for use with Spring Social. CONFIDENTIAL 29
  • 30. Additional Resources § Slides: • http://portal.sliderocket.com/vmware/Native-Android-Development-with-Spring § Project Home: • http://www.springsource.org/spring-android § Sample Code: • https://github.com/SpringSource/spring-android-samples § Webinar: • http://www.springsource.org/node/3505 § Blog Posts: • http://blog.springsource.com/author/rclarkson/ CONFIDENTIAL 30