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

Close a poll

Copy link

You can close a poll by specifying the pollId in the closePoll() method.

KotlinKTX
fun closePoll(channel: GroupChannel, pollId: Long) {
    channel.closePoll(pollId) { poll, e ->
        if (e != null) {
            // Handle error.
        }

        // The poll has been successfully closed.
        // Update or check `closeAt` here to reflect the change in the UI.
    }
}

PollHandler

Copy link

Through PollHandler, the Sendbird server always notifies whether your poll has been successfully closed.

fun interface PollHandler {
    fun onResult(poll: Poll?, e: SendbirdException?)
}

The closeAt property

Copy link

When integrating polls in your application, managing the closeAt property is crucial for a smooth user experience. Here are guidelines for handling this property effectively:

1. Message list (Channel view)

Copy link
  • Closed polls: When rendering a list of messages, check if the poll's closeAt time is in the past compared to the current time. If it is, display the poll using a "closed" UI state. Note that differences between device and server time might affect this comparison.

2. Real-time updates in channels

Copy link
  • Active channel scenario: If a user is already in a chanel and remains in a channel past the closeAt time, implement a real-time timer to check closeAt against the current time and update the UI accordingly.

3. Re-entering a channel

Copy link
  • UI update on re-entry: Make sure the UI updates correctly to show the poll's closed state if closeAt has passed while the user was away in another view.

4. User interactions with closed polls

Copy link
  • Error handling: Prevent users from interacting with closed polls by updating the UI and handling errors appropriately if they attempt to vote after closeAt.

5. Standalone poll screens

Copy link
  • Consistent logic: Apply the same real-time checks and UI updates in standalone poll views as in message lists.