English | Site Directory

Android - An Open Handset Alliance Project

android.view
public final class

android.view.UIThreadUtilities

java.lang.Object
android.view.UIThreadUtilities

In Android, Views must be manipulated only from the UI thread. This class offers various utility methods to abide by this contract. Because different view hierarchys can run in different threads, the UI thread is unique to a specific view hierarchy only. For this reason, the methods exposed in this class must be supplied with a View whose UI thread will be used.

Summary

Public Constructors

          UIThreadUtilities()

Public Methods

      static  boolean  isUIThread(View view)
Indicates whether the code is currently executing in the UI thread of a specified view.
      static  void  runOnUIThread(Dialog dialog, Runnable action)
Runs the specified action on the UI thread.
      static  void  runOnUIThread(View view, Runnable action)
Runs the specified action on the UI thread.
      static  void  runOnUIThread(Activity activity, Runnable action)
Runs the specified action on the UI thread.
Methods inherited from class java.lang.Object

Details

Public Constructors

public UIThreadUtilities()

Public Methods

public static boolean isUIThread(View view)

Indicates whether the code is currently executing in the UI thread of a specified view.

Parameters

view the view whose UI thread must be checked, must be attached to a window

Returns

  • true if this method executes in the supplied view's UI thread

Throws

IllegalArgumentException if the specified view is not attached to a window

public static void runOnUIThread(Dialog dialog, Runnable action)

Runs the specified action on the UI thread. If the current thread is the UI thread, then the action is executed immediately. If the current thread is not the UI thread, the action is posted to the event queue of the UI thread.

Parameters

dialog the dialog whose UI thread must be used
action the action to run on the UI thread

Throws

IllegalArgumentException if the specified dialog is not attached to a window

public static void runOnUIThread(View view, Runnable action)

Runs the specified action on the UI thread. If the current thread is the UI thread, then the action is executed immediately. If the current thread is not the UI thread, the action is posted to the event queue of the UI thread.

Parameters

view the view whose UI thread must be used, must be attached to a window
action the action to run on the UI thread

Throws

IllegalArgumentException if the specified view is not attached to a window

public static void runOnUIThread(Activity activity, Runnable action)

Runs the specified action on the UI thread. If the current thread is the UI thread, then the action is executed immediately. If the current thread is not the UI thread, the action is posted to the event queue of the UI thread.

Parameters

activity the activity whose UI thread must be used
action the action to run on the UI thread

Throws

IllegalArgumentException if the specified activity is not attached to a window
Build m5-rc15g - 14 May 2008 12:50