org.androidannotations.annotations
Annotation Type UiThread


@Retention(value=CLASS)
@Target(value=METHOD)
public @interface UiThread

Should be used on method that must be run in the Ui thread

The annotated method MUST return void and MAY contain parameters.

The generated code is based on a local Handler instance.

Delay

Sometimes you may want to delay execution of a Ui thread method. To do so, you should use the delay() field.

Example :
 @EBean
 public class MyBean {
 
        @UiThread(delay = 2000)
        void uiThreadTask() {
                // ...
        }
 }
 

Execution flow

Prior to 3.0, UiThread annotated method calls was always added in the handler execution queue to ensure that execution was done in Ui thread. In 3.0, we kept the same behavior for compatibility purpose.

But, if you want to optimize UiThread calls, you may want to change propagation() value to REUSE. In this configuration, the code will make a direct call to the method if current thread is already Ui thread. If not, we're falling back to handler call.

Example :
 @EBean
 public class MyBean {
 
        @UiThread
        void uiThreadTask() {
                // This code is executed via the handler
                // The following method will be directly executed instead of using
                // handler
                uiThreadTaskReused();
        }
 
        @UiThread(propagation = REUSE)
        void uiThreadTaskReused() {
                // ...
        }
 }
 

See Also:
Background, Handler

Optional Element Summary
 long delay
           
 UiThread.Propagation propagation
          If propagation = REUSE, the method will check first if it is inside the UI thread already.
 

delay

public abstract long delay
Default:
0L

propagation

public abstract UiThread.Propagation propagation
If propagation = REUSE, the method will check first if it is inside the UI thread already. If so, it will directly call the method instead of using the handler. The default value is ENQUEUE, which will always call the handler.

Returns:
Default:
org.androidannotations.annotations.UiThread.Propagation.ENQUEUE


Copyright © 2010-2014. All Rights Reserved.