@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
The delay of the execution in milliseconds.
|
UiThread.Propagation |
propagation
If propagation is
UiThread.Propagation.REUSE , the method will check first
if it is inside the UI thread already. |
public abstract long delay
public abstract UiThread.Propagation propagation
UiThread.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
UiThread.Propagation.ENQUEUE
, which will always call the handler.UiThread.Propagation.ENQUEUE
to always call the handler,
UiThread.Propagation.REUSE
, to check whether it is already on the
UI threadCopyright © 2010-2015. All Rights Reserved.