Example usage for android.os Handler getLooper

List of usage examples for android.os Handler getLooper

Introduction

In this page you can find the example usage for android.os Handler getLooper.

Prototype

public final Looper getLooper() 

Source Link

Usage

From source file:Main.java

public static boolean isHandlerThread(Handler handler) {
    return Thread.currentThread().equals(handler.getLooper().getThread());
}

From source file:Main.java

/**
 * Checks whether the current thread is the same thread that the {@link Handler} is associated
 * with.//from  w  w  w . j  a v  a 2 s .c om
 * @return true if the current thread is the same thread that the {@link Handler} is associated
 * with; otherwise false.
 */
public static boolean checkThreadAccess(Handler handler) {
    return Looper.myLooper() == handler.getLooper();
}

From source file:io.realm.Realm.java

/**
 * All changes since {@link io.realm.Realm#beginTransaction()} are persisted to disk and the
 * Realm reverts back to being read-only. An event is sent to notify all other realm instances
 * that a change has occurred. When the event is received, the other Realms will get their
 * objects and {@link io.realm.RealmResults} updated to reflect
 * the changes from this commit./* w w  w  . j  a  v  a2s.com*/
 *
 * @throws java.lang.IllegalStateException If the write transaction is in an invalid state or incorrect thread.
 */
public void commitTransaction() {
    checkIfValid();
    transaction.commitAndContinueAsRead();

    for (Map.Entry<Handler, String> handlerIntegerEntry : handlers.entrySet()) {
        Handler handler = handlerIntegerEntry.getKey();
        String realmPath = handlerIntegerEntry.getValue();

        // Notify at once on thread doing the commit
        if (handler.equals(this.handler)) {
            sendNotifications();
            continue;
        }

        // For all other threads, use the Handler
        if (realmPath.equals(configuration.getPath()) // It's the right realm
                && !handler.hasMessages(REALM_CHANGED) // The right message
                && handler.getLooper().getThread().isAlive() // The receiving thread is alive
        ) {
            handler.sendEmptyMessage(REALM_CHANGED);
        }
    }
}