Java Code Examples for com.facebook.react.bridge.UiThreadUtil#isOnUiThread()

The following examples show how to use com.facebook.react.bridge.UiThreadUtil#isOnUiThread() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * @return a MessageQueueThreadImpl corresponding to Android's main UI thread.
 */
private static MessageQueueThreadImpl createForMainThread(
    String name,
    QueueThreadExceptionHandler exceptionHandler) {
  Looper mainLooper = Looper.getMainLooper();
  final MessageQueueThreadImpl mqt =
      new MessageQueueThreadImpl(name, mainLooper, exceptionHandler);

  if (UiThreadUtil.isOnUiThread()) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
  } else {
    UiThreadUtil.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
          }
        });
  }
  return mqt;
}
 
Example 2
@Override
public void reloadSettings() {
  if (UiThreadUtil.isOnUiThread()) {
    reload();
  } else {
    UiThreadUtil.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        reload();
      }
    });
  }
}
 
Example 3
@Override
public void onEventDispatch(final Event event) {
  // Events can be dispatched from any thread so we have to make sure handleEvent is run from the
  // UI thread.
  if (UiThreadUtil.isOnUiThread()) {
    handleEvent(event);
  } else {
    UiThreadUtil.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        handleEvent(event);
      }
    });
  }
}