Skip to main content
Events enable a decoupled, flexible architecture in the CometChat UI Kit. Components and Composite Components emit events in response to user interactions or state changes, allowing other parts of your application to react without direct references between components.

When to use this

  • You need to update your UI when a user is blocked or unblocked.
  • You need to respond to group actions such as member joins, kicks, bans, or ownership transfers.
  • You need to track conversation deletions or updates in real time.
  • You need to react to messages being sent, edited, deleted, or read.
  • You need to handle call lifecycle events (outgoing, accepted, rejected, ended).
  • You need to respond to UI-level events such as panel visibility changes or active chat changes.

Prerequisites

  • The cometchat-chat-uikit-android dependency added to your project.
  • CometChatUIKit.init() called and completed successfully.
  • A logged-in CometChat user (call CometChatUIKit.login() before registering listeners).

API reference

User Events

CometChatUserEvents emits events when the logged-in user executes actions on another user. This class provides methods to add and remove listeners for user events, as well as methods to handle specific user actions such as blocking and unblocking users. Events:
EventDescription
ccUserBlockedTriggered when the logged-in user blocks another user.
ccUserUnblockedTriggered when the logged-in user unblocks another user.
Listener registration:
CometChatUserEvents.addUserListener(LISTENERS_TAG, object : CometChatUserEvents() {
    override fun ccUserBlocked(user: User) {
        // Perform action when user is blocked
    }

    override fun ccUserUnblocked(user: User) {
        // Perform action when user is unblocked
    }
})
What this does: Registers a listener on CometChatUserEvents using a unique LISTENERS_TAG. The ccUserBlocked callback fires when the logged-in user blocks another user, and ccUserUnblocked fires when the logged-in user unblocks another user.

Group Events

CometChatGroupEvents emits events when the logged-in user performs actions related to groups. This class provides methods to listen to various group-related events and handle them. Events:
EventDescription
ccGroupCreatedTriggered when the logged-in user creates a group.
ccGroupDeletedTriggered when the logged-in user deletes a group.
ccGroupLeftTriggered when the logged-in user leaves a group.
ccGroupMemberScopeChangedTriggered when the logged-in user changes the scope of another group member.
ccGroupMemberBannedTriggered when the logged-in user bans a group member from the group.
ccGroupMemberKickedTriggered when the logged-in user kicks another group member from the group.
ccGroupMemberUnbannedTriggered when the logged-in user unbans a user banned from the group.
ccGroupMemberJoinedTriggered when the logged-in user joins a group.
ccGroupMemberAddedTriggered when the logged-in user adds new members to the group.
ccOwnershipChangedTriggered when the logged-in user transfers the ownership of their group to some other member.
Listener registration:
CometChatGroupEvents.addGroupListener(LISTENERS_TAG, new CometChatGroupEvents() {
    @Override
    public void ccGroupCreated(Group group) {
        // Perform action when group is created
    }

    @Override
    public void ccGroupDeleted(Group group) {
        // Perform action when group is deleted
    }

    @Override
    public void ccGroupLeft(Group group) {
        // Perform action when user leaves group
    }

    @Override
    public void ccGroupMemberScopeChanged(Group group, User user, String scope) {
        // Perform action when group member scope is changed
    }

    @Override
    public void ccGroupMemberBanned(Group group, User user, User bannedBy) {
        // Perform action when user is banned from group
    }

    @Override
    public void ccGroupMemberKicked(Group group, User kickedUser, User kickedBy) {
        // Perform action when user is kicked from group
    }

    @Override
    public void ccGroupMemberUnbanned(Group group, User user, User unbannedBy) {
        // Perform action when user is unbanned from group
    }

    @Override
    public void ccGroupMemberJoined(Group group, User joinedUser) {
        // Perform action when user joins group
    }

    @Override
    public void ccGroupMemberAdded(Group group, List<User> addedMembers, User addedBy) {
        // Perform action when members are added to group
    }

    @Override
    public void ccOwnershipChanged(Group group, User newOwner, User oldOwner) {
        // Perform action when group ownership is changed
    }
});
What this does: Registers a listener on CometChatGroupEvents using a unique LISTENERS_TAG. Each callback fires when the logged-in user performs the corresponding group action — creating, deleting, leaving a group, or managing members (scope change, ban, kick, unban, join, add, ownership transfer).

Conversation Events

CometChatConversationEvents emits events when the logged-in user performs actions related to conversations. This allows the UI to be updated when conversations change. Events:
EventDescription
ccConversationDeletedTriggered when the logged-in user deletes a conversation.
ccUpdateConversationTriggered when there is an update in the conversation.
Listener registration:
CometChatConversationEvents.addListener("LISTENERS_TAG", object : CometChatConversationEvents() {
    override fun ccConversationDeleted(conversation: Conversation) {
        // Perform action when conversation is deleted
    }
})
What this does: Registers a listener on CometChatConversationEvents using a unique listener tag. The ccConversationDeleted callback fires when the logged-in user deletes a conversation, and ccUpdateConversation fires when a conversation is updated.

Message Events

CometChatMessageEvents emits events when various actions are performed on messages within the application. These events facilitate updating the UI when messages change. Events:
EventDescription
ccMessageSentTriggered whenever a logged-in user sends any message. It can have two states: inProgress and sent.
ccMessageEditedTriggered whenever a logged-in user edits any message from the list of messages. It can have two states: inProgress and sent.
ccMessageDeletedTriggered whenever a logged-in user deletes any message from the list of messages.
ccMessageReadTriggered whenever a logged-in user reads any message.
ccLiveReactionTriggered whenever a logged-in user clicks on live reaction.
onFormMessageReceivedTriggered when a form message is received.
onCardMessageReceivedTriggered when a card message is received.
onCustomInteractiveMessageReceivedTriggered when a custom interactive message is received.
onInteractionGoalCompletedTriggered when an interaction goal is completed.
onSchedulerMessageReceivedTriggered when a scheduler message is received.
Listener registration:
CometChatMessageEvents.addListener("UNIQUE_ID", object : CometChatMessageEvents() {
    override fun ccMessageSent(baseMessage: BaseMessage?, status: Int) {
        // Perform action when message is sent
    }

    override fun ccMessageEdited(baseMessage: BaseMessage?, status: Int) {
        // Perform action when message is edited
    }

    override fun ccMessageDeleted(baseMessage: BaseMessage?) {
        // Perform action when message is deleted
    }

    override fun ccMessageRead(baseMessage: BaseMessage?) {
        // Perform action when message is read
    }

    override fun ccLiveReaction(icon: Int) {
        // Perform action on live reaction
    }

    // Other overridden methods for handling specific message types and actions
})
What this does: Registers a listener on CometChatMessageEvents using a unique ID string. The callbacks fire for message lifecycle events — sending, editing, deleting, reading messages, and reacting with live reactions. Additional overrides handle interactive message types (onFormMessageReceived, onCardMessageReceived, onCustomInteractiveMessageReceived, onInteractionGoalCompleted, onSchedulerMessageReceived).

Call Events

CometChatCallEvents emits events related to calls within the application. This class provides methods to listen to call-related events and handle them. Events:
EventDescription
ccOutgoingCallTriggered when the logged-in user initiates an outgoing call.
ccCallAcceptedTriggered when a call is accepted.
ccCallRejectedTriggered when a call is rejected.
ccCallEndedTriggered when a call is ended.
Listener registration:
CometChatCallEvents.addListener("ListenerID", new CometChatCallEvents() {
    @Override
    public void ccOutgoingCall(Call call) {
        // Perform action when outgoing call is initiated
    }

    @Override
    public void ccCallAccepted(Call call) {
        // Perform action when call is accepted
    }

    @Override
    public void ccCallRejected(Call call) {
        // Perform action when call is rejected
    }

    @Override
    public void ccCallEnded(Call call) {
        // Perform action when call is ended
    }
});
What this does: Registers a listener on CometChatCallEvents using a unique "ListenerID". The callbacks fire for each stage of the call lifecycle — initiating an outgoing call, accepting, rejecting, and ending a call.

UI Events

CometChatUIEvents emits events related to UI components within the CometChat UI Kit. This class provides methods to listen to UI-related events and handle them. Events:
EventDescription
showPanelTriggered to show an additional UI panel with custom elements.
hidePanelTriggered to hide a previously shown UI panel.
ccActiveChatChangedTriggered when the active chat changes, providing information about the current message, user, and group.
ccOpenChatTriggered to open a chat with a specific user or group.
Listener registration:
CometChatUIEvents.addListener("UNIQUE_ID", new CometChatUIEvents() {
    @Override
    public void showPanel(HashMap<String, String> id, UIKitConstants.CustomUIPosition alignment, Function1<Context, View> view) {
        // Perform action to show UI panel with custom elements
    }

    @Override
    public void hidePanel(HashMap<String, String> id, UIKitConstants.CustomUIPosition alignment) {
        // Perform action to hide UI panel
    }

    @Override
    public void ccActiveChatChanged(HashMap<String, String> id, BaseMessage message, User user, Group group) {
        // Perform action when active chat changes
    }

    @Override
    public void ccOpenChat(User user, Group group) {
        // Perform action to open a chat with a specific user or group
    }
});
What this does: Registers a listener on CometChatUIEvents using a unique ID string. The callbacks fire for UI-level actions — showing or hiding custom panels, reacting to active chat changes, and opening a chat with a specific user or group.

Removing event listeners

Each event listener class provides methods to add and remove listeners. If you register a listener, remove it when the component or activity is destroyed to prevent memory leaks. Use the same tag or ID string you passed during registration.

Common pitfalls and fixes

PitfallFix
Forgetting to remove event listeners when an activity or fragment is destroyed, causing memory leaks and duplicate callbacks.Remove your event listeners in your onDestroy() or onDestroyView() lifecycle callback, using the same tag you passed during registration.
Using a non-unique or hardcoded listener tag, causing one listener to overwrite another.Use a unique string for each listener registration (for example, the class name or a UUID). If two registrations share the same tag, only the last one receives callbacks.
Registering a listener after the event has already fired, so the callback is never triggered.Register your event listeners early in the component lifecycle (for example, in onCreate() or onViewCreated()), before any user interaction that could trigger the event.
Expecting Kotlin-style nullable parameters in Java callbacks (or vice versa).Match the parameter types to the language you are using. In Kotlin, message event callbacks use nullable types (for example, BaseMessage?), while Java callbacks use non-nullable types (for example, BaseMessage).
Not handling all relevant callbacks in a listener, causing missed events.Override every callback method you need. If you register a CometChatGroupEvents listener but only override ccGroupCreated, you will not receive ccGroupMemberJoined or other group events.
Assuming events fire on the main thread and updating UI directly without checking.Wrap UI updates inside runOnUiThread {} (Kotlin) or runOnUiThread(() -> { }) (Java) to ensure thread safety when handling event callbacks.

FAQ

How do I listen for multiple event types at the same time? Register separate listeners for each event class. For example, register a CometChatUserEvents listener and a CometChatMessageEvents listener independently, each with its own unique tag or ID. There is no single listener that covers all event categories. What is the difference between UI Kit events and SDK-level listeners? UI Kit events (for example, CometChatMessageEvents, CometChatUserEvents) are emitted by UI Kit components when the logged-in user performs actions through the UI. SDK-level listeners (from the core CometChat SDK) handle real-time events from the server, such as incoming messages from other users. Use UI Kit events to keep your UI in sync with user-initiated actions, and SDK-level listeners for server-pushed updates. Do I need to remove listeners if my activity is finishing? Yes. If you do not remove listeners in onDestroy() or onDestroyView(), the listener reference persists and can cause memory leaks or duplicate callback invocations when the activity or fragment is recreated. Can I register the same listener tag twice? If you call addListener or addUserListener/addGroupListener with the same tag, the second registration replaces the first. Only the most recently registered listener for that tag receives callbacks. Why does my conversation event listener only show ccConversationDeleted in Kotlin but both events in Java? The Kotlin code sample in the original documentation demonstrates only the ccConversationDeleted override. The ccUpdateConversation callback is available in both languages. Override ccUpdateConversation in your Kotlin listener to receive conversation update events.

Next steps