/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Enter and exit an open channel

Copy link

A user can enter up to ten open channels and only receives messages from the entered channels. If the user is disconnected from the Sendbird server with the disconnect() method, they no longer receive messages. To continue receiving messages from the user's participating open channels, they have to be reconnected to the server with the connect() method and re-enter the open channels.

If the client app is in the background, the user is disconnected from the Sendbird server. However, when the client app runs in the foreground again, the Chat SDK automatically reconnects the open channels the user has entered. When a user temporarily loses connection to the Sendbird server due to an unstable connection, the SendbirdChat instance attempts to reconnect the user and the open channels the user has entered.

KotlinKTX
OpenChannel.getChannel(CHANNEL_URL) { channel, e ->
    if (e != null) {
        // Handle error.
    }

    // Invoke the callback handler.
    channel?.enter { enterError ->
        if (enterError != null) {
            // Handle error.
        }

        // The current user successfully enters the open channel
        // and can chat with other users in the channel by using APIs.
    }
}

A user can exit open channels as shown below. After exiting, the user can no longer receive messages from the channel.

KotlinKTX
OpenChannel.getChannel(CHANNEL_URL) { channel, e ->
    if (e != null) {
        // Handle error.
    }

    // Invoke the callback handler.
    channel?.exit { exitError ->
        if (e != null) {
            // Handle error.
        }

        // The current user successfully exits the open channel.
    }
}