Skip to main content
CometChat provides real-time event listeners to keep your app updated with live changes. These listeners notify your app when messages are received, users come online/offline, group membership changes occur, calls are initiated, and connection state changes.
Listener Cleanup Required: Always remove listeners when they’re no longer needed (e.g., on widget dispose or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.
CometChat provides 7 listener types:
  1. MessageListener
  2. UserListener
  3. GroupListener
  4. CallListener
  5. ConnectionListener
  6. LoginListener
  7. AIAssistantListener

Message Listener

The MessageListener class provides you with live events related to messages. Below are the callback methods provided by the MessageListener class.

MessageListener Events

To add the MessageListener, you need to use the addMessageListener() method provided by the CometChat class.
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the activity/fragment where the MessageListener is declared is not in use, you need to remove the listener using the removeMessageListener() method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the onPause() method of the activity/fragment.

User Listener

The UserListener class provides you with live events related to users. Below are the callback methods provided by the UserListener class.

UserListener Events

To add the UserListener, you need to use the addUserListener() method provided by the CometChat class.
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the activity/fragment where the UserListener is declared is not in use, you need to remove the listener using the removeUserListener() method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the onPause() method of the activity/fragment.

Group Listener

The GroupListener class provides you with all the real-time events related to groups. Below are the callback methods provided by the GroupListener class.

GroupListener Events

To add the GroupListener, you need to use the addGroupListener() method provided by the CometChat class.
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the activity/fragment where the GroupListener is declared is not in use, you need to remove the listener using the removeGroupListener() method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the onPause() method of the activity/fragment.

Call Listener

The CallListener class provides you with real-time events related to calls. Below are the callback methods provided by the CallListener class.

CallListener Events

To add the CallListener, you need to use the addCallListener() method provided by the CometChat class.
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the CallListener is no longer needed, remove it using the removeCallListener() method.

Connection Listener

The ConnectionListener class provides you with real-time events related to the WebSocket connection status. Below are the callback methods provided by the ConnectionListener class.

ConnectionListener Events

To add the ConnectionListener, you need to use the addConnectionListener() method provided by the CometChat class.
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the ConnectionListener is no longer needed, remove it using the removeConnectionListener() method.

Login Listener

The LoginListener class provides you with real-time events related to user authentication. Below are the callback methods provided by the LoginListener class.

LoginListener Events

To add the LoginListener, you need to use the addLoginListener() method provided by the CometChat class.
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the LoginListener is no longer needed, remove it using the removeLoginListener() method.

AI Assistant Listener

The AIAssistantListener class provides you with real-time events related to AI assistant interactions. Below are the callback methods provided by the AIAssistantListener class.

AIAssistantListener Events

To add the AIAssistantListener, you need to use the addAIAssistantListener() method provided by the CometChat class.
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the AIAssistantListener is no longer needed, remove it using the removeAIAssistantListener() method.

Next Steps

Receive Messages

Handle incoming messages in real-time using message listeners

User Presence

Track when users come online or go offline

Typing Indicators

Show real-time typing status in conversations

Delivery & Read Receipts

Track message delivery and read status

Connection Status

Monitor SDK connection to CometChat servers

Login Listeners

Monitor user login and logout events