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.
Community comments
Spring Android framework
by Naresh Chintalcheru,
Is that even a good idea?
by peter lin,
Re: Is that even a good idea?
by Jonathan Allen,
Re: Is that even a good idea?
by peter lin,
Summer is here!
by C Curl,
negative comments?..interesting...
by Jeryl Cook,
I expect more from Spring for Android
by Alexey Mitrov,
Spring Android framework
by Naresh Chintalcheru,
Your message is awaiting moderation. Thank you for participating in the discussion.
Limited functionality, like to see this framework evolve.
Is that even a good idea?
by peter lin,
Your message is awaiting moderation. Thank you for participating in the discussion.
Let me get this straight. Mobile devices need to be efficient and use a little memory as necessary. So the solution is to put spring on it? Shouldn't a server handle all these types of social networking operations? Why bog down a mobile device?
Is this all part of Spring's plans for world domination?
Summer is here!
by C Curl,
Your message is awaiting moderation. Thank you for participating in the discussion.
like the article says, just use j2se http libraries with jackson/json. No point in taking in the sugar coated bloatware in spring just to save handful of lines of code.
Re: Is that even a good idea?
by Jonathan Allen,
Your message is awaiting moderation. Thank you for participating in the discussion.
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.
Re: Is that even a good idea?
by peter lin,
Your message is awaiting moderation. Thank you for participating in the discussion.
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,
Your message is awaiting moderation. Thank you for participating in the discussion.
Spring is bloatware???, Spring should only be used on server???
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
I expect more from Spring for Android
by Alexey Mitrov,
Your message is awaiting moderation. Thank you for participating in the discussion.
As I came into Android from J2EE I try to apply some patterns fron Enterprise. One is dependency injection as it heps get structured application with huge number of components and a lot of dependencies. But I was disapointed Spring did not provide it for Android. So I create my own for my projects as open source project. If you are interesting, please look at andromeda.webuda.com/