Skip to content
JoanZapata edited this page Dec 19, 2014 · 17 revisions

About AsyncService

AsyncService is a library which helps you to manage threads, cache, and errors on Android in a declarative way, using annotations. That make your code a lot shorter, and it allows you to focus on the business code.

Global AsyncService position

It can be used for many purposes, but the lib has been developed for the very common situation where you need a layer between your activities and your rest client. It's an alternative to Android's AsyncTask, Loader and/or Service, with much more features and shorter code.

No more anonymous callbacks!

As you know as an Android developer, you can't make a network call on the UI thread, and on the other hand you can't touch UI elements on any other thread than this one. So you need to manage threading. For most library, threading is done using asynchronous methods and callback interfaces to implement. On the user side, it usually implies a lot of anonymous classes, with multiple methods to implement to manage different results such as onSuccess(), onFailure(), etc…

AsyncService relies on messages. The basic idea is that you call a method, and then you wait for it's return type to be sent as a message. Same goes for error handling.

void anyMethod(){
   service.getUser("Joan");
}

@OnMessage
void onUserReceived(User user){
   // ...
}

@OnMessage
void onError(UserNotFound error){
   // ...
}

Another good side of it is that instead of having a single error callback where you need to manage all different cases with instanceof, using messages you can send strongly-typed errors (see UserNotFound above), with only the relevant fields in it.

Learn

  • Learn the basics.
  • How to [enhance your service](Enhance Service).
  • How to [take advantage of caching](Caching Patterns).
  • How to [handle exceptions](Handle Exceptions).
  • Want more? See what's [behind the scenes](Behind The Scenes).

License

Copyright 2014 Joan Zapata

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Home

Learn

  1. Learn the basics.
  2. How to [enhance your service](Enhance Service).
  3. Take advantage of [caching](Caching Patterns).
  4. How to [handle exceptions](Handle Exceptions).
  5. Want more? See what's [behind the scenes](Behind The Scenes).
Clone this wiki locally
You can’t perform that action at this time.