@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.
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() { // ... } }
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() { // ... } }
Background
,
Handler
Modifier and Type | Optional Element and Description |
---|---|
long |
delay |
UiThread.Propagation |
propagation
If propagation = REUSE, the method will check first if it is inside the
UI thread already.
|
public abstract long delay
public abstract UiThread.Propagation propagation
Copyright © 2010-2014. All Rights Reserved.