Home
Kiss is a library which helps you to manage threading
, 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.
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.
As you all know, on Android you can't make a network call on the UI thread, and on the other hand you can't touch UI element on any other thread than the UI thread. So you need to manage threading/asynchronous methods. For most library, threading implies callbacks, and callbacks implies anonymous classes, with multiple methods to manage different results such as success, failure, etc… Until Java 8 reaches Android, it's very hard to keep the code readable with so many callbacks. Kiss 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:
void anyMethod(){
service.getUser("Joan");
}
@OnMessage
void onUserReceived(User user){
// ...
}
@OnMessage
void onError(UserDoesNotExist 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 UserDoesNotExist
above), with only the relevant fields in it.
- Learn the basics
- How to [enhance your service](Enhance Service)
- How to [handle exceptions](Handle Exceptions).
- [Behind the scenes](Behind The Scenes)
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.
Created by Joan Zapata.
- Learn the basics.
- How to [enhance your service](Enhance Service).
- Take advantage of [caching](Caching Patterns).
- How to [handle exceptions](Handle Exceptions).
- Want more? See what's [behind the scenes](Behind The Scenes).