SpringSource Brings Spring Framework to Android with Spring for Android 1.0
SpringSource has released Spring for Android 1.0. Spring for Android is an extension of the Spring Framework that helps simplify the development of native Android applications. This release features a REST client (RestTemplate) and OAuth support (Spring Social).
The first feature of Spring for Android 1.0 is the REST client. You can now use the Spring RestTemplate abstraction to consume RESTful services within your native Android application. Based on Google's recommendations, RestTemplate uses the J2SE HTTP client libraries for Android 2.3+, and HttpClient for Android 2.2 and below. It supports different HTTP Message Converters, and uses Jackson or Gson for JSON marshalling, Simple XML Serializer for XML marshalling, and Android ROME for RSS/Atom marshalling. RestTemplate also supports gzip compression. Here's a basic example of RestTemplate taken from the Spring for Android reference manual, which queries Google for the search term "SpringSource".
String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}";
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
String result = restTemplate.getForObject(url, String.class, "SpringSource");
The other major feature of Spring for Android 1.0 is Spring Social support. You now have the ability to use Spring Social in your Android applications, which includes an OAuth client and implementations of popular social websites like Twitter and Facebook. This release provides OAuth 1.x and 2.0 support, and includes a SQLite repository, and Android compatible Spring Security encryption.
Developers familiar with the Spring Framework will naturally expect Dependency Injection to be part of Spring for Android. However, due to the way Android drives the application lifecycle using Intents, the way Dependency Injection can be implemented is limited. Please read Clean Code in Android Applications for more information on Dependency Injection options in Android.
For more information, please read the Spring for Android Reference Manual. Spring for Android examples are available at GitHub. To get started, you can download the release distribution, or add the Maven dependencies.
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-rest-template</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-auth</artifactId>
<version>${spring-android-version}</version>
</dependency>
Be sure to read Maven Dependency Management to utilize Maven's dependency management capabilities within an Android application.
Spring Android framework
by
Naresh Chintalcheru
Is that even a good idea?
by
peter lin
Is this all part of Spring's plans for world domination?
Summer is here!
by
C Curl
Re: Is that even a good idea?
by
Jonathan Allen
Re: Is that even a good idea?
by
peter lin
It's a horrible idea on the server, let alone a mobile device. But as smart phone CPUs continue to improve, we're probably going to see a lot more poeple trying to get away with this kind of thing.
I agree it's horrible either way. Of course, people will still do it. Then again, I'm not a fan of social networking websites, or using Spring from first hand experience.
negative comments?..interesting...
by
Jeryl Cook
Sounds like some posters need to read on what the Spring framework is suppose to solve first.
Spring Application Framework is simply implements Inversion of Control, and dependency injection, you...which by itself is very light pattern...in this Android release it "Injects" Httpclient, used via RestTemplate..., which one uses anyway when making HTTP client calls...
light reading:
martinfowler.com/articles/injection.html
Educational Content
Co-making Great Products
Jeff Patton May 22, 2013




Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think