> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Transient Messages

> Send and receive ephemeral real-time messages with the CometChat Android SDK for live reactions and temporary indicators.

Transient messages are messages that are sent in real-time only and are not saved or tracked anywhere. The receiver of the message will only receive the message if he is online and these messages cannot be retrieved later.

## Send a Transient Message

You can use the `sendTransientMessage()` method to send a transient message to a user or in a group. The receiver will receive this information in the `onTransientMessageReceived()` method of the `MessageListener` class. In order to send the transient message, you need to use the [`TransientMessage`](/sdk/reference/auxiliary#transientmessage) class.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    String receiverId = "cometchat-uid-2";
    String receiverType = CometChatConstants.RECEIVER_TYPE_USER;

    JSONObject data = new JSONObject();
    data.put("LIVE_REACTION", "heart");
    TransientMessage transientMessage = new TransientMessage(uid, CometChatConstants.RECEIVER_TYPE_USER, data);
    CometChat.sendTransientMessage(transientMessage);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val receiverId = "cometchat-uid-2"
    val receiverType = CometChatConstants.RECEIVER_TYPE_USER

    val data = JSONObject()
    data.put("LIVE_REACTION", "heart")
    val transientMessage = TransientMessage(uid, CometChatConstants.RECEIVER_TYPE_USER, data)
    CometChat.sendTransientMessage(transientMessage)
    ```
  </Tab>
</Tabs>

## Real-time Transient Messages

Use `onTransientMessageReceived` in `MessageListener` to receive transient messages.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.addMessageListener("UNIQUE_LISTENER_ID", new CometChat.MessageListener() {
      @Override
      public void onTransientMessageReceived(TransientMessage transientMessage) {
        Log.d(TAG, "Transient message received with data : " + transientMessage.getData());  
      }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    CometChat.addMessageListener("UNIQUE_LISTENER_ID", object : MessageListener() {
      override fun onTransientMessageReceived(transientMessage: TransientMessage) {
        Log.d(TAG, "Transient message received with data : " + transientMessage.data)
      }
    }) 
    ```
  </Tab>
</Tabs>

The `TransientMessage` class consists of the below parameters:

| Parameter        | Information                                                                                                                                |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| **sender**       | An object of the [`User`](/sdk/reference/entities#user) class holding all the information. related to the sender of the transient message. |
| **receiverId**   | Unique Id of the receiver. This can be the Id of the group or the user the transient message is sent to.                                   |
| **receiverType** | The type of the receiver - `CometChatConstants.RECEIVER_TYPE_USER` or `CometChatConstants.RECEIVER_TYPE_GROUP`                             |
| **data**         | A JSONObject to provide data.                                                                                                              |

<Warning>
  Always remove listeners when they're no longer needed (e.g., in `onDestroy()` or when navigating away). Failing to remove listeners can cause memory leaks and duplicate event handling.
</Warning>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Send Messages" icon="paper-plane" href="/sdk/android/send-message">
    Send text, media, and custom messages that are stored and retrievable
  </Card>

  <Card title="Receive Messages" icon="envelope" href="/sdk/android/receive-messages">
    Handle real-time message delivery with message listeners
  </Card>

  <Card title="Typing Indicators" icon="keyboard" href="/sdk/android/typing-indicators">
    Show real-time typing status for users and groups
  </Card>

  <Card title="Real-Time Listeners" icon="bell" href="/sdk/android/real-time-listeners">
    Learn about all available real-time event listeners
  </Card>
</CardGroup>
