Added in API level 1

MessageQueue


class MessageQueue
kotlin.Any
   ↳ android.os.MessageQueue

Low-level class holding the list of messages to be dispatched by a Looper. Messages are not added directly to a MessageQueue, but rather through Handler objects associated with the Looper.

You can retrieve the MessageQueue for the current thread with Looper.myQueue().

Summary

Nested classes
abstract

Callback interface for discovering when a thread is going to block waiting for more messages.

abstract

A listener which is invoked when file descriptor related events occur.

Public methods
Unit

Add a new IdleHandler to this message queue.

Unit

Adds a file descriptor listener to receive notification when file descriptor related events occur.

Boolean

Returns true if the looper has no pending messages which are due to be processed.

Unit

Remove an IdleHandler from the queue that was previously added with addIdleHandler.

Unit

Removes a file descriptor listener.

Protected methods
Unit

Public methods

addIdleHandler

Added in API level 1
fun addIdleHandler(handler: MessageQueue.IdleHandler): Unit

Add a new IdleHandler to this message queue. This may be removed automatically for you by returning false from IdleHandler.queueIdle() when it is invoked, or explicitly removing it with removeIdleHandler.

This method is safe to call from any thread.

Parameters
handler MessageQueue.IdleHandler: The IdleHandler to be added. This value cannot be null.

addOnFileDescriptorEventListener

Added in API level 23
fun addOnFileDescriptorEventListener(
    fd: FileDescriptor,
    events: Int,
    listener: MessageQueue.OnFileDescriptorEventListener
): Unit

Adds a file descriptor listener to receive notification when file descriptor related events occur.

If the file descriptor has already been registered, the specified events and listener will replace any that were previously associated with it. It is not possible to set more than one listener per file descriptor.

It is important to always unregister the listener when the file descriptor is no longer of use.

Parameters
fd FileDescriptor: The file descriptor for which a listener will be registered. This value cannot be null.
events Int: The set of events to receive: a combination of the OnFileDescriptorEventListener.EVENT_INPUT, OnFileDescriptorEventListener.EVENT_OUTPUT, and OnFileDescriptorEventListener.EVENT_ERROR event masks. If the requested set of events is zero, then the listener is unregistered. Value is either 0 or a combination of android.os.MessageQueue.OnFileDescriptorEventListener#EVENT_INPUT, android.os.MessageQueue.OnFileDescriptorEventListener#EVENT_OUTPUT, and android.os.MessageQueue.OnFileDescriptorEventListener#EVENT_ERROR
listener MessageQueue.OnFileDescriptorEventListener: The listener to invoke when file descriptor events occur. This value cannot be null.

isIdle

Added in API level 23
fun isIdle(): Boolean

Returns true if the looper has no pending messages which are due to be processed.

This method is safe to call from any thread.

Return
Boolean True if the looper is idle.

removeIdleHandler

Added in API level 1
fun removeIdleHandler(handler: MessageQueue.IdleHandler): Unit

Remove an IdleHandler from the queue that was previously added with addIdleHandler. If the given object is not currently in the idle list, nothing is done.

This method is safe to call from any thread.

Parameters
handler MessageQueue.IdleHandler: The IdleHandler to be removed. This value cannot be null.

removeOnFileDescriptorEventListener

Added in API level 23
fun removeOnFileDescriptorEventListener(fd: FileDescriptor): Unit

Removes a file descriptor listener.

This method does nothing if no listener has been registered for the specified file descriptor.

Parameters
fd FileDescriptor: The file descriptor whose listener will be unregistered. This value cannot be null.

Protected methods

finalize

Added in API level 1
protected fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method