Play with this demo
In this Activity, you can :
- start a SpiceRequest and observe the result : getting a list of tweets about android ;
- cancel a started request ;
- start a request, rotate the device and observe that UI is updated as expected (result is cached by RoboSpice);
- rotate the device as much as you want, even during loading, RoboSpice is robust and will update the results as soon as they arrive;
- a request is sent on demand only. When a new activity is created, cache is used. You only update the Tweets if you want to.
- try to delay the requests by 10 seconds, send a request, leave the activity, come back and you will get the results.
If previous results were stored in cache, you get them, if results are pending, you get them when they arrive
.
- send requests as often as you want, requests will be aggregated automatically.
- delay the requests by 10 seconds, send a request, leave the activity, leave the app (by any mean : home button, go to another app, phone call, etc.) and you
will get the results.
- you can even delay the requests by 10 seconds, send a request, kill the app using the task switcher, reopen the app and the activity, and you will get the results,
updated by new ones if a request was pending.
- switch off the phone, reopen the activity, result is displayed as it is cached on disk.
- observe no more memory leak, you can start as many requests as you want.
RoboSpiced basic tweeter client.
This Activity uses a RoboSpice request to get the list of Tweets related to android.
RoboSpice overview
RobSpice is new approach to asynchronous networking on Android. Its principles are simple :
- it is designed primarily for network requests but in practice it can execute any asyncrhonous job.
- activities, services, applications, broadcast receivers can send requests via RoboSpice, all contexts can use it.
- requests are transferred to an Android Service (a SpiceService) and executed within the context of this service.
This provides a stable context to actually perform the asynchronous job.
- the context of origin plugs listeners to the request result and progress. The listeners are automatically removed according to
the life cycle of the context of origin : there is no memory leak if RoboSpice is used correctly.
- listeners will be notified on the main thread of the context, i.e the UI Thread for activities, including for progress.
- RoboSpice provides automatic caching of network results. Many different formats are available : binary, text, json, xml, ormlite.
- RoboSpice is fully object oriented : you get POJOs as the result of network requests, and can submit POJOs to the requests if desired.
There is *no restrictions on the POJOs used* to submit a request or on the result type of the request.
Moreover there is no need to decompose/re-compose your POJOs to a bundle or to a set of primitive types or Serializable, RoboSpice is pure OO.
- RoboSpice handles asynchronous exceptions in a clear and robust way.
- RoboSpice provides out of the box support for REST requests using Spring Android. This support is provided by a separate module and
other network implementations are possible. We believe RoboSpice creates the most suitable way to use spring android, it's not an alternative to it.
We believe that these features far outperform other techniques to implement a modern REST client for android
and providing users with data as fresh as possible.
RoboSpice is not an alternative to . In this example, we use both of them thanks to the Spring Android RoboSpice module.
We believe RoboSpice is the best way to use Spring Android
Progress and RoboSpice
On this demo activity, you can observe the progress of the RoboSpice job, or some of it.
Some progress information is displayed near the tweet list header. Current download progress is not available due to limitations of libraries used
internally by Spring Android.
Canceling the request
RoboSpice requests can be cancelled easily and this applies to this example as well.
Note that, once REST request is sent, it can't be aborted, this is another limitation of Spring Android.
We provide additional examples of RoboSpice capabilities in the next Activities...