Skip to main content
With offline support turned on, the Android UI Kit reads from the Chat SDK’s on-device cache. Chats the user has opened before appear at once, even with no connection. Text messages and voice notes sent while offline wait in a queue and go out when the connection returns. Every list shows a clear state when it has nothing saved and can’t reach the server. Both kits get the same behaviour: Kotlin (XML Views) and Jetpack Compose. Where the API differs, this page shows a tab for each. The UI Kit builds on the Chat SDK’s offline support, and this page covers what the UI Kit adds on top. For cache settings, encryption, media caching and sync, see the Android SDK offline docs.

Overview

Works offline:
  • Conversations, users, groups and group members you have loaded before show at once from the cache.
  • Saved message history, including threads, opens without a connection.
  • New text messages and voice notes are queued and sent automatically on reconnect. So are messages sent with CometChatUIKit.sendTextMessage, sendMediaMessage and sendCustomMessage. A queued message shows a clock and Not sent yet until it is sent.
  • Images, videos, audio and files that are on the device open from the saved copy, with media caching on (the default).
  • After a reconnect, the Chat SDK’s catch-up brings in what changed while the user was away.
Needs a connection:
  • The first load of any chat or list that was never opened before.
  • Keyword search with no saved match.
  • Uploading photos, videos, audio files or documents picked in the composer’s attachment tray (enableMultipleAttachments, on by default). The message can be sent once its files have uploaded.
  • Editing or deleting a sent message, adding or removing a reaction, and pinning or saving a message. These aren’t queued.
  • Message information, call logs and calls.
  • AI Assistant chat history that was never loaded. Saved history shows offline.
  • Media that has no copy on the device.

Requirements

UI Kit 6.3.0 is the first version with offline support. It brings in Chat SDK 5.1.2, so don’t add chat-sdk-android yourself. Add the kit you use:
build.gradle.kts
To encrypt the cache, also add the SQLCipher engine. The Chat SDK and the UI Kit don’t bundle it:
build.gradle.kts
If you call encryption(true) without adding SQLCipher, the cache doesn’t open and the app works online only (the default encryptionFailureBehavior). See Encrypt the Cache.

Enable offline support

Offline support is off by default. Turn it on by passing an OfflineConfig to setOfflineConfig() on the UIKitSettings builder, before you call build() and CometChatUIKit.init(). The UI Kit passes the config straight to the Chat SDK and stores nothing of its own. The code is the same for both kits.
OfflineConfig has more options, such as cache size, retention, the pending-message limit, encryption and media caching. Set only the ones you need. Every option is described in the Configuration & API Reference.
Offline support is active only while a user is logged in. Call CometChat.isOfflineEnabled() at the moment you need to know. See Enable Offline Support.
When the user is already logged in, CometChatUIKit.login() with the same UID, and CometChatUIKit.loginWithAuthToken(), answer at once from the saved session, without a network call. So an app that logs in on every launch still opens offline after a restart.

How the components behave offline

Lists: Conversations, Users, Groups and Group Members

  • Saved rows show first. The server page then loads and updates the list in place.
  • Rows already on screen stay when a load can’t reach the server. With rows on screen, a failure caused by having no connection shows no error view.
  • With nothing saved and no connection, the list shows Connect to load chats (or users, groups, members) as its error view and calls onError. This state has no Retry button. A custom error view replaces it, and hiding the error state hides it (see Your own empty and error views). The list loads by itself when the connection returns.
  • A list opened with a filter but no keyword, such as online users, behaves like a plain list and shows Connect to load ….
  • Only an empty page from the server ends paging.
  • In the conversation list, a chat whose last message is your own unsent message shows a clock, or a failed icon once sending failed.
A keyword search in a list with no saved match while offline shows Connect to search with a second line, Search needs an internet connection. It doesn’t call onError. When the connection returns, the search runs again. CometChatSearch shows the same Connect to search state when its search can’t reach the server and nothing saved matches. A search showing that state runs again when the connection returns. Mention suggestions in the composer show saved users or members first. Typing a name after the @ needs a connection.

Message list and threads

  • Saved history shows at once. Older and newer pages come from the cache first, then from the server.
  • A chat that was never saved, opened offline, shows Connect to load messages and calls onError. It loads by itself when the connection returns.
  • When the list reaches the end of the saved messages with no connection, it shows Connect to load more at that edge. Tap it to try again. On reconnect, each blocked edge loads once by itself, older first.
  • Jumping to a message, or starting from the first unread message, opens the list around that message from the cache when the device is offline.
  • When a refresh after reconnecting brings newer messages while the user is scrolled up, a Jump to latest pill appears. The reading position stays until the user taps it or scrolls to the bottom.
  • With media caching on (the default), images, videos, audio and files show the on-device copy first. With no copy and no connection, the bubble shows a placeholder with the file name, size and Media will be available when back online. It shows the media again when the connection returns. Tapping the placeholder while connected downloads the file. With media caching off, the bubble loads the media from its URL and shows no placeholder.

Composer and unsent messages

  • A text message or voice note sent while offline appears at once with a clock and Not sent yet under the bubble. It goes out automatically on reconnect.
  • Photos, videos, audio files and documents picked in the attachment tray are not queued. Each file starts uploading as soon as it’s picked, and uploading needs a connection, so the message can’t be sent until its files have uploaded. A tile whose upload failed shows a retry control: tap it to upload that file again once you’re back online. If the file’s saved copy is missing, the tile shows File not saved. Remove it and add it again. instead. With offline support on, the Chat SDK keeps the files staged in a chat’s tray for that chat, so they come back when the chat is opened again. With enableMultipleAttachments set to false, a picked file is sent as a single media message instead, and is queued like a voice note.
  • An unsent message (waiting or failed) offers only Retry, Delete and, for text, Copy in its long-press menu. It offers no Reply, React, Edit, Pin, Save or Message info until it has been sent. The visibility settings you use for message options still apply.
  • A failed message shows Not sent. Tap to retry under the bubble in red. Tap that line to retry. In the Kotlin kit the failed status icon retries too; in Jetpack Compose, tapping the failed message retries it. Screen readers announce the action as “Retry”.
  • Retry asks the Chat SDK to send the queued message again. A message that failed before it was queued is sent again as a new send. While a retry waits for the connection, the message shows Not sent yet again.
  • Delete removes the unsent message from the device.
  • If the message is no longer waiting to be sent (for example, it was removed after you left the group), Retry and Delete remove it from the list.
  • If the message is being sent at that moment, Retry and Delete change nothing and the list shows Sending… try again in a moment.
  • A full queue shows Too many messages waiting to send. A file that is too big for the offline media cache shows File too large to send offline. A queued message that the Chat SDK removes shows 1 unsent message was removed.

Presence

While the Chat SDK isn’t connected, nobody shows as online: there’s no online dot in the conversations, users or group members lists, and no “Online” or “last seen” subtitle in the message header. Presence shows again once the SDK is connected.

Pinned, Saved, Reactions and Notifications

CometChatPinnedMessages, CometChatSavedMessages, the reaction list and CometChatNotificationFeed follow the same rules as the other lists. Rows cached on the device show first. With nothing saved and no connection, they show Connect to load messages, Connect to load reactions or Connect to load notifications. The reaction list keeps its tabs visible and shows Connect to load reactions below them. The pinned, saved, reaction and notification screens load by themselves when the connection returns.

Logout and user switch

Cached data belongs to the logged-in user. The Chat SDK deletes the user’s offline cache on logout and when a different user logs in. On logout or a user switch, the UI Kit also clears every list on screen before the next user’s first frame. Any message still waiting to be sent is discarded, and a pending CometChatUIKit send answers with ERROR_OFFLINE_MESSAGE_DISCARDED. See Send completions.

Offline states and texts

Override any of these texts by adding the same key to your app’s res/values/strings.xml, as described in Localize. Both kits read the same string resources, and every language the UI Kit ships includes them. Notices show as a short toast, once each.

Errors and callbacks

When onError fires

With offline support on, every list follows the same rules:
  • Rows on screen, no connection: the rows stay. No error view, no onError.
  • Rows on screen, any other error: the rows stay. onError fires once if the user or your app started the load: opening the screen, a refresh, a new keyword or a jump. A reload the UI Kit starts itself after a reconnect or a cache reset stays quiet, and so does a failed next page while scrolling.
  • Nothing on screen, no connection: the Connect to load … state shows, and onError fires once. In the Kotlin message list, onError doesn’t fire when the error state is hidden (setHideErrorState(true)).
  • Nothing on screen, any other error: the error view shows, and onError fires. It has a Retry button, except in the Kotlin message list and reaction list.
  • Keyword search offline with nothing saved: Connect to search shows, with no onError.
  • Empty server answer: the normal empty view.

Send completions

CometChatUIKit.sendTextMessage, sendMediaMessage and sendCustomMessage answer each send once:
  • onSuccess fires when the server accepts the message.
  • onError fires when sending fails for good.
  • A send that is only queued (offline) calls neither. It answers when the message is sent or fails.
  • If the user logs out, switches user, or the offline cache is reset before the message was sent, onError fires once with the error code ERROR_OFFLINE_MESSAGE_DISCARDED. Don’t show an error for it: the message row going away is the only visible signal.
The UI Kit’s own senders (the composer, stickers and smart replies) handle this case themselves and show no error. The MessageSent event on CometChatEvents.messageEvents keeps its meaning: IN_PROGRESS once when the message is queued, SUCCESS when it is sent, and ERROR when it fails for good. A discarded message (logout, user switch or cache reset) fires no ERROR.

Pin and save

Pinning, unpinning, saving and unsaving need a connection. On the device that made the change, the UI Kit updates the message, the Pinned and Saved screens and the MessagePinned / MessageUnpinned / MessageSaved / MessageUnsaved events when the call succeeds (its onSuccess). With Chat SDK 5.1.2, which this UI Kit brings in, the SDK sends no listener event back to that device. See Pin & Save Messages.

Offline events

CometChatEvents.offlineEvents is a flow of CometChatOfflineEvent. It never emits while offline support is off.
For the Chat SDK’s own reasons and error codes, see the Configuration & API Reference.

Customization

Unsent message caption style

CometChatOfflineRowStyle styles the Not sent yet and Not sent. Tap to retry lines under unsent messages. By default they use the theme’s caption text, secondary text colour and error colour.
You can also set cometchatOfflineNotSentTextAppearance and cometchatOfflineFailedMessageTint in your app theme.

Hide offline notices

Hides the offline notice toasts, such as Too many messages waiting to send or Unsent messages may have been lost. Notices that aren’t about one chat (messages were not sent, unsent messages were lost and Unsent messages may have been lost) are shown once, on the next Conversations or Message List that doesn’t hide notices; if every list hides them, they aren’t shown. A chat’s own notices, such as Too many messages waiting to send, File too large to send offline or Sending… try again in a moment, aren’t shown anywhere. The Connect to load more row and the Jump to latest pill still show. Default false.

Your own empty and error views

  • If you set a custom error view (setErrorView / errorView), it shows instead of the UI Kit’s Connect to load … state.
  • If you hide the error state (setHideErrorState(true) / hideErrorState = true), no offline state shows.
  • If you set a custom empty view (setEmptyView / emptyView), it shows instead of Connect to search. Hiding the empty state hides it.

With offline support turned off

Apps that don’t turn on offline support keep today’s behaviour, with these exceptions in UI Kit 6.3.0:
  • Chat SDK 5.1.2. The UI Kit brings in Chat SDK 5.1.2, whether or not offline is on. If your unit tests stub fetchNext(any()) or fetchPrevious(any()) on SDK request classes such as ConversationsRequest, give the matcher a type: the SDK now has a second overload of these methods.
  • Kotlin reaction list error state. A reaction list that fails to load now shows its error text, or your custom error view, below the tabs instead of an empty sheet. Jetpack Compose already did this.

Limitations and known issues

  • Keyword search with no saved match, message information, call logs and AI Assistant chat history that was never loaded need a connection.
  • Edits, deletes, reactions, pins and saves aren’t queued. They need a connection when the user makes them.
  • Files picked in the attachment tray need a connection to upload.
  • Media downloaded for offline use is stored unencrypted on the device. The message cache itself can be encrypted. See Encrypt the Cache.

Next steps

SDK offline overview

How the Chat SDK caches and syncs data

Configuration & API Reference

Every OfflineConfig option, listener and error code

Send While Offline

The SDK’s queue, retry and discard

Stay in Sync

Catch-up after reconnect and cache resets

Message List

Message list properties and styling

Localize

Override the offline texts