Skip to main content
Quick Reference for AI Agents & Developers
// Leave a group
CometChat.leaveGroup("GUID", object : CometChat.CallbackListener<String>() {
    override fun onSuccess(message: String) { }
    override fun onError(e: CometChatException) { }
})

// Listen for member left events
CometChat.addGroupListener("LISTENER_ID", object : GroupListener() {
    override fun onGroupMemberLeft(action: Action?, leftUser: User?, leftGroup: Group?) { }
})
Available via: SDK | REST API | UI Kits

Leave a Group

To stop receiving updates and messages for any particular joined group, you need to leave the group using the leaveGroup() method.
private String GUID = "GUID";

CometChat.leaveGroup(GUID, new CometChat.CallbackListener<String>() {
  @Override
  public void onSuccess(String successMessage) {
    Log.d(TAG, successMessage);
  }

  @Override
  public void onError(CometChatException e) {
    Log.d(TAG, "Group leaving failed with exception: " + e.getMessage());
  }
});
ParameterDescription
GUIDThe GUID of the group you would like to leave
Once a group is left, the user will no longer receive any updates or messages pertaining to the group.

Real-Time Group Member Left Events

As a member of a group, how do I know if someone has left it when my app is running? If a user leaves a group, the members of the group receive a real-time event in the onGroupMemberLeft() method of the GroupListener class.
CometChat.addGroupListener(UNIQUE_LISTENER_ID, new CometChat.GroupListener() {
  @Override
  public void onGroupMemberLeft(Action action, User leftUser, Group leftGroup) {
    Log.d(TAG, "User left");
  }
});

Missed Group Member Left Events

As a member of a group, how do I know if someone has left it when my app is not running? When you retrieve the list of previous messages, if a member has left any group that the logged-in user is a member of, the list of messages will contain an Action message. An Action message is a sub-class of the BaseMessage class. For the group member left event, in the Action object received, the following fields can help you get the relevant information:
  1. action - left
  2. actionBy - User object containing the details of the user who left the group
  3. actionFor - Group object containing the details of the group the user has left
Always remove group 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.

Best Practices

Prompt users to confirm before leaving a group, especially for private groups where rejoining requires an invitation.
After leaving a group, consider clearing cached messages and group data from local storage to free up space.
Update your UI immediately when receiving leave events to reflect the current group membership status.

Troubleshooting

Symptom: leaveGroup() fails with “Not a member” error.Cause: User is not currently a member of the group.Solution: Check the hasJoined property of the Group object before attempting to leave.
Symptom: leaveGroup() fails when trying to leave as the last admin.Cause: Groups require at least one admin. The last admin cannot leave without transferring ownership or deleting the group.Solution: Either transfer ownership to another member or delete the group if you want to remove it entirely.

Next Steps