Skip to content
pyricau edited this page Jan 14, 2012 · 12 revisions

Since AndroidAnnotations 1.0

Get rid of ASyncTasks!!

@Background

The @Background annotation indicates that an activity method will run in a thread other than the ui thread.

The method must not be private and must not declare throwing any exception.

Usage example:

void myMethod() {
    someBackgroundWork("hello", 42);
}

@Background
void someBackgroundWork(String aParam, long anotherParam) {
    [...]
}

void someBackgroundWork(String aParam, long anotherParam) { [...] }


>In fact, `@Background` is not strictly equivalent to the previous code : we use a shared cached [thread pool executor](http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool%28%29) to prevent creating too much threads.

## @UiThread

The `@UiThread` annotation indicates that an activity **method** will run in the [ui thread](http://developer.android.com/guide/topics/fundamentals.html#threads).

The method must not be private and must not declare throwing any exception.

Usage example:
```java
void myMethod() {
    doInUiThread("hello", 42);
}

@UiThread
void doInUiThread(String aParam, long anotherParam) {
    [...]
}

@UiThreadDelayed

The @UiThreadDelayed annotation indicates that an activity method will run in the ui thread, after the specified amount of time elapses.

The method must not be private and must not declare throwing any exception.

Usage example:

void myMethod() {
    doInUiThreadDelayed("hello", 42);
}

@UiThreadDelayed(2000)
void doInUiThreadDelayed(String aParam, long anotherParam) {
    [...]
}

No more AsyncTask<Param, Progress, Result>!!

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally