Skip to main content
Version: 5.21.0

SDK initialization

The ChatCenterUI class is the entry point to the SDK. Create one instance in Application.onCreate() and use it for the entire application lifecycle.

Constructor

ChatCenterUI(appContext: Context, logger: ChatLoggerConfig? = null)
ParameterTypeRequiredDefaultDescription
appContextContextYesYour app's applicationContext
loggerChatLoggerConfig?NonullLogger configuration. See Logger
caution

Pass applicationContext, not an Activity context — otherwise the constructor throws IllegalArgumentException. This guards against potential memory leaks.

Properties

  • val version: String — current SDK version (read-only). Useful for logging and error reports.

  • var theme: ChatTheme? — light chat theme. Set before calling init(...). ChatTheme has three mutually exclusive constructors — pick one customization level:

    // Level 1 — colors, images, typography via design tokens:
    chatCenterUI.theme = ChatTheme(context, colors = myColors, images = myImages, typography = myTypography)
    // Level 2 — overriding ready-made UI components:
    chatCenterUI.theme = ChatTheme(chatComponents)
    // Level 3 — entire screen flows (maximum flexibility):
    chatCenterUI.theme = ChatTheme(chatFlows)

    The level-1 constructor also has a texts: ChatTexts parameter (between images and typography), but it is deprecated — override strings via your app's strings.xml.

  • var darkTheme: ChatTheme? — dark theme. If not set, the SDK always uses the light theme:

    chatCenterUI.darkTheme = ChatTheme(darkComponents)

    For details on the differences between the forms and on ChatColors / ChatComponents / ChatFlows — see Design system → Themes.

Synchronous initialization: init()

fun init(providerUid: String, config: ChatConfig)
fun init(providerUid: String, appMarker: String, config: ChatConfig)
ParameterTypeRequiredDescription
providerUidStringYesApplication identifier issued by edna. In the edna Chat Center admin panel, it is shown as Provider ID on the Android channel's "Setup" tab — see Connecting the Android mobile chat
appMarkerStringOnly in the 2nd overloadApplication marker within a single platform
configChatConfigYesConnection and behavior parameters. See ChatConfig

appMarker is needed when several Android apps work under the same providerUid (e.g., prod and staging) — it allows the edna server to distinguish them when routing messages and in analytics. If you have a single app, use the init(providerUid, config) overload without appMarker. The specific appMarker value is coordinated with edna during integration.

init() — before any other SDK calls

init(...) must be called before authorize(...), handlePushMessage(...) / handleFCMMessage(...) — any such call before init() completes leads to IllegalStateException.

The getChatFragment() / getChatActivity() methods do not throw — they return null if the corresponding screen is not open yet (including before init()).

Call init(...) once — typically in Application.onCreate(). A repeated call is not supported as a public contract.

Async initialization: initAsync()

fun initAsync(
providerUid: String,
config: ChatConfig,
coroutineContext: CoroutineContext = Dispatchers.Main,
onInitComplete: () -> Unit = {}
)

fun initAsync(
providerUid: String,
appMarker: String,
config: ChatConfig,
coroutineContext: CoroutineContext = Dispatchers.Main,
onInitComplete: () -> Unit = {}
)

Use it when the configuration is loaded from the server or when initialization should not block the main thread.

ParameterTypeRequiredDefaultDescription
providerUidStringYesApplication identifier issued by edna
appMarkerStringOnly in the 2nd overloadApplication marker within a single platform
configChatConfigYesConnection and behavior parameters. See ChatConfig
coroutineContextCoroutineContextNoDispatchers.MainContext in which initialization runs. Use Dispatchers.Default / Dispatchers.IO for background
onInitComplete() -> UnitNo{}Callback after initialization completes (see the caution below about the UI thread)
chatCenterUI.initAsync(
providerUid = "YOUR_PROVIDER_UID",
config = chatConfig
) {
// SDK is initialized — you can call authorize()
chatCenterUI.authorize(chatUser, chatAuth)
}
onInitComplete and the UI thread

The onInitComplete callback runs on the same coroutineContext that was passed to initAsync(...). If you pass Dispatchers.Default or Dispatchers.IO, wrap any UI access (showing a fragment, navigation, dialogs) inside the callback in withContext(Dispatchers.Main) { ... }. With the default (Dispatchers.Main), no additional wrapping is required.

Async init + push handling

When using initAsync(), push notification handling in FirebaseMessagingService.onMessageReceived() must be deferred until the onInitComplete callback fires. Calling handlePushMessage() or handleFCMMessage() before init completes may cause message loss.

  • Quick start — three steps to opening the chat for the first time.
  • Lifecycle — where exactly to call init in your app's architecture.
  • ChatConfig parameters — the complete list of configuration fields.