RoboSpice is an Android Library that makes it easier to write asynchronous network requests. It is production-ready, open sourced and includes a large range of features.
Mobile Apps are content driven : They basically display content delivered through Web services. RoboSpice eases writing those network requests. Web Services Network Requests Data Base
An asynchronous way to execute code. • A clean encapsulated way to group asynchronous code and callback code. • The ability to execute callback code in the UI thread (allow to manipulate widgets). onPreExecute onPostExecute onProgressUpdate doInBackground
Async Task Activity New Activity Async Task AsyncTasks have one BIG trouble : They are poorly tied to the activity life cycle ! u An activity can die during asynchronous code execution. u Callback will be executed even if activity is not showing up anymore and any attempt to manipulate widgets will crash the app or fail, at best. → AsyncTask create memory leaks ! u It is possible to improve the link between AsyncTask and Activities, but you need a lot of code and caution to achieve this. → Loaders to the rescue Process
public PersonLoader(Context context) { super(context); } @Override public List<Person> loadInBackground() { return dataSourceOrDomainModel.getListPerson( progressHandler ); } } Loaders have been designed for cursors, they don't fit when it comes to networking : Asynchronous code is too tied to Activity life cycle. • Request's result is lost when you leave the Activity. • If you leave the Activity, request dies : users MUST wait for result • (they can go to other apps but not to other activities within the app). • Exception management is left to the dev without any support. • And code is a bit bloated by generics...
Service to process network requests. RoboSpice is designed for asynchronous networking. Activity Spice Manager Spice Service Request Listener Request notify listeners update UI execute process
any Android Context : requests and results can be accessed from all of them. Application Service Activity Activity Fragment Spice Manager Spice Manager Spice Manager Spice Manager Spice Manager Spice Service
that eases writing asynchronous network requests. It executes requests inside an Android Service. It provides transparent caching. It supports REST out of the box, using Spring Android. RoboSpice features A FULLY OBJECT ORIENTED API POJOs are used to send requests parameters POJOs are used to receive request results There is no restriction on POJO classes used There is no need to implement Serializable or Parcelable. NO MEMORY LEAK, OPTIMAL RESOURCE USAGE Activity / Service life cycles are fully managed There is no memory leak at all Requests are not lost when sender dies Requests results are never lost when sender dies AUTOMATIC CACHING OF REQUESTS RESULTS Caching is fully automatic Supports various formats : XML, JSON, ORM Lite, Text Strings, Binary data EASY TO USE Listeners’ methods are invoked on UI Thread Intuitive API Ease writing integration tests Documentated Available on Maven Central Available on GitHub : http://goo.gl/lw5C7