> ## 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.

# Join Group

> Join public, private, and password-protected CometChat groups with the Android SDK using GUIDs and group passwords.

<Accordion title="AI Integration Quick Reference">
  ```kotlin theme={null}
  // Join a public group
  CometChat.joinGroup("GUID", CometChatConstants.GROUP_TYPE_PUBLIC, "", 
      object : CometChat.CallbackListener<Group>() {
          override fun onSuccess(group: Group) { }
          override fun onError(e: CometChatException) { }
      })

  // Join a password-protected group
  CometChat.joinGroup("GUID", CometChatConstants.GROUP_TYPE_PASSWORD, "password123", callback)
  ```
</Accordion>

## Join a Group

Use `joinGroup()` to start participating in a group conversation.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    private String GUID = "GUID";
    private String groupType = CometChatConstants.GROUP_TYPE_PUBLIC;
    private String password = "";

    CometChat.joinGroup(GUID, groupType, password, new CometChat.CallbackListener<Group>() {
      @Override
      public void onSuccess(Group joinedGroup) {
        Log.d(TAG, joinedGroup.toString());
      }
      @Override
      public void onError(CometChatException e) {
        Log.d(TAG, "Group joining failed with exception: " + e.getMessage());
      }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val GUID:String="GUID"
    val groupType:String=CometChatConstants.GROUP_TYPE_PUBLIC
    val password:String=""


    CometChat.joinGroup(GUID,groupType,password,object:CometChat.CallbackListener<Group>(){
      override fun onSuccess(p0: Group?) {
        Log.d(TAG, p0.toString());
      }
      override fun onError(p0: CometChatException?) {
        Log.d(TAG, "Group joining failed with exception: " + p0?.message)
      }
    })
    ```
  </Tab>
</Tabs>

The `joinGroup()` method takes the following parameters:

| Parameter   | Description                                                                                                                                                                                                             |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GUID`      | The GUID of the group you would like to join                                                                                                                                                                            |
| `groupType` | Type of the group. CometChat provides 3 types of groups: 1. `CometChatConstants.GROUP_TYPE_PUBLIC` (public) 2. `CometChatConstants.GROUP_TYPE_PASSWORD` (password) 3. `CometChatConstants.GROUP_TYPE_PRIVATE` (private) |
| `password`  | Password is mandatory for password-protected groups.                                                                                                                                                                    |

Once you have joined a group successfully, you can send and receive messages in that group.

CometChat keeps track of the groups you have joined, so you do not need to join the group every time you want to communicate in it.

You can identify if a group is joined using the `hasJoined` parameter in the [`Group`](/sdk/reference/entities#group) object.

## Real-Time Group Member Joined Events

When a user joins a group, members receive a real-time event in `onGroupMemberJoined()` of the `GroupListener` class. The callback provides an [`Action`](/sdk/reference/messages#action) object, the joined [`User`](/sdk/reference/entities#user), and the [`Group`](/sdk/reference/entities#group).

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.addGroupListener(UNIQUE_LISTENER_ID, new CometChat.GroupListener() {
      @Override
      public void onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup) {
        Log.d(TAG, "User joined");
      }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    CometChat.addGroupListener(UNIQUE_LISTENER_ID, object : GroupListener() {
      override fun onGroupMemberJoined(action: Action?, joinedUser: User?, joinedGroup: Group?) {
        Log.d(TAG, "User joined")
      }
    })
    ```
  </Tab>
</Tabs>

## Missed Group Member Joined Events

When fetching message history, if a member joined a group the logged-in user is part of, the list will contain an [`Action`](/sdk/reference/messages#action) message with these fields:

1. `action` - `joined`
2. `actionBy` - [`User`](/sdk/reference/entities#user) object containing the details of the user who joined the group
3. `actionFor` - [`Group`](/sdk/reference/entities#group) object containing the details of the group the user has joined

<Warning>
  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.
</Warning>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Leave Group" icon="user-minus" href="/sdk/android/leave-group">
    Leave groups you no longer want to participate in
  </Card>

  <Card title="Retrieve Members" icon="users" href="/sdk/android/retrieve-group-members">
    Fetch list of group members
  </Card>

  <Card title="Send Messages" icon="paper-plane" href="/sdk/android/send-message">
    Start sending messages in the group
  </Card>

  <Card title="Group Listeners" icon="bell" href="/sdk/android/real-time-listeners">
    Handle real-time group events
  </Card>
</CardGroup>
