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)
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
appContext | Context | Yes | — | Your app's applicationContext |
logger | ChatLoggerConfig? | No | null | Logger configuration. See Logger |
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 callinginit(...).ChatThemehas 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: ChatTextsparameter (betweenimagesandtypography), but it is deprecated — override strings via your app'sstrings.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)
| Parameter | Type | Required | Description |
|---|---|---|---|
providerUid | String | Yes | Application 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 |
appMarker | String | Only in the 2nd overload | Application marker within a single platform |
config | ChatConfig | Yes | Connection 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(...) 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.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
providerUid | String | Yes | — | Application identifier issued by edna |
appMarker | String | Only in the 2nd overload | — | Application marker within a single platform |
config | ChatConfig | Yes | — | Connection and behavior parameters. See ChatConfig |
coroutineContext | CoroutineContext | No | Dispatchers.Main | Context in which initialization runs. Use Dispatchers.Default / Dispatchers.IO for background |
onInitComplete | () -> Unit | No | {} | 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)
}
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.
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.
Related sections
- Quick start — three steps to opening the chat for the first time.
- Lifecycle — where exactly to call
initin your app's architecture. - ChatConfig parameters — the complete list of configuration fields.