Example usage for android.os Handler hasMessages

List of usage examples for android.os Handler hasMessages

Introduction

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

Prototype

public final boolean hasMessages(int what) 

Source Link

Document

Check if there are any pending posts of messages with code 'what' in the message queue.

Usage

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.//from   w  ww. j a  va 2  s . 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);
        }
    }
}