Added in API level 1

Messenger


class Messenger : Parcelable
kotlin.Any
   ↳ android.os.Messenger

Reference to a Handler, which others can use to send messages to it. This allows for the implementation of message-based communication across processes, by creating a Messenger pointing to a Handler in one process, and handing that Messenger to another process.

Note: the implementation underneath is just a simple wrapper around a Binder that is used to perform the communication. This means semantically you should treat it as such: this class does not impact process lifecycle management (you must be using some higher-level component to tell the system that your process needs to continue running), the connection will break if your process goes away for any reason, etc.

Summary

Inherited constants
Public constructors
Messenger(target: Handler!)

Create a new Messenger pointing to the given Handler.

Messenger(target: IBinder!)

Create a Messenger from a raw IBinder, which had previously been retrieved with getBinder.

Public methods
Int

Boolean
equals(other: Any?)

Comparison operator on two Messenger objects, such that true is returned then they both point to the same Handler.

IBinder!

Retrieve the IBinder that this Messenger is using to communicate with its associated Handler.

Int

static Messenger!

Convenience function for reading either a Messenger or null pointer from a Parcel.

Unit
send(message: Message!)

Send a Message to this Messenger's Handler.

static Unit

Convenience function for writing either a Messenger or null pointer to a Parcel.

Unit
writeToParcel(out: Parcel, flags: Int)

Properties
static Parcelable.Creator<Messenger!>

Public constructors

Messenger

Added in API level 1
Messenger(target: Handler!)

Create a new Messenger pointing to the given Handler. Any Message objects sent through this Messenger will appear in the Handler as if Handler.sendMessage(Message) had been called directly.

Parameters
target Handler!: The Handler that will receive sent messages.

Messenger

Added in API level 1
Messenger(target: IBinder!)

Create a Messenger from a raw IBinder, which had previously been retrieved with getBinder.

Parameters
target IBinder!: The IBinder this Messenger should communicate with.

Public methods

describeContents

Added in API level 1
fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

equals

Added in API level 1
fun equals(other: Any?): Boolean

Comparison operator on two Messenger objects, such that true is returned then they both point to the same Handler.

Parameters
obj the reference object with which to compare.
otherObj This value may be null.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

getBinder

Added in API level 1
fun getBinder(): IBinder!

Retrieve the IBinder that this Messenger is using to communicate with its associated Handler.

Return
IBinder! Returns the IBinder backing this Messenger.

hashCode

Added in API level 1
fun hashCode(): Int
Return
Int a hash code value for this object.

readMessengerOrNullFromParcel

Added in API level 1
static fun readMessengerOrNullFromParcel(in: Parcel!): Messenger!

Convenience function for reading either a Messenger or null pointer from a Parcel. You must have previously written the Messenger with writeMessengerOrNullToParcel.

Parameters
in Parcel!: The Parcel containing the written Messenger.
Return
Messenger! Returns the Messenger read from the Parcel, or null if null had been written.

send

Added in API level 1
fun send(message: Message!): Unit

Send a Message to this Messenger's Handler.

Parameters
message Message!: The Message to send. Usually retrieved through Message.obtain().
Exceptions
android.os.RemoteException Throws DeadObjectException if the target Handler no longer exists.

writeMessengerOrNullToParcel

Added in API level 1
static fun writeMessengerOrNullToParcel(
    messenger: Messenger!,
    out: Parcel!
): Unit

Convenience function for writing either a Messenger or null pointer to a Parcel. You must use this with readMessengerOrNullFromParcel for later reading it.

Parameters
messenger Messenger!: The Messenger to write, or null.
out Parcel!: Where to write the Messenger.

writeToParcel

Added in API level 1
fun writeToParcel(
    out: Parcel,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 1
static val CREATOR: Parcelable.Creator<Messenger!>