API Reference
Everything below is a member of the OneSygnal object (a singleton — there’s no
factory/constructor).
Callback-based methods
| Method | Signature | Notes |
|---|---|---|
initialize | (context: Context, completion: ((Boolean) -> Unit)? = null) | Completion fires once config/user/surveys are fully fetched and settled, with true; or as soon as possible with false if init couldn’t proceed (e.g. no resolvable API key). Calling it again while already initialized invokes the completion with true immediately and does nothing else. |
track | (eventName: String, properties: Map<String, Any?> = emptyMap()): Boolean | Synchronous, no completion — returns false if not initialized or surveys are disabled, otherwise true. No I/O happens inline; the event is queued and flushed on an internal timer. |
identify | (userId: String, attributes: Map<String, Any?>? = null, completion: ((Boolean) -> Unit)? = null) | Completion resolves false immediately if not yet initialized. On success, re-fetches surveys if the last fetch was more than 60s ago. |
logout | (completion: (() -> Unit)? = null) | No-op with an immediate completion call if not initialized. |
reset | (completion: (() -> Unit)? = null) | Clears the identified user, mints a new anonymous ID, re-fetches surveys. No-op if not initialized. |
setApiKey | (apiKey: String) | Override for the manifest-read API key. Must be called before initialize(). |
setLocale | (locale: String) | Live-reactive if called after initialize() — see Configuration. |
setSurveysEnabled | (enabled: Boolean) | In-memory flag, works whether or not initialized. |
areSurveysEnabled | (): Boolean | Default true. |
isInitialized | (): Boolean | |
on | (event: String, callback: (Any?) -> Unit): Registration | See Events. Always returns a Registration synchronously — no “not ready yet” case like Web’s loader. |
shutdown | (completion: (() -> Unit)? = null) | Flushes pending events, tears down listeners/timers, sets initialized = false. No-op if not initialized. |
flush is absent
There’s no public manual-flush method on Android. Events and responses are flushed on their own
internal periodic timers, with no hook for a caller to trigger an early flush — Web’s flush()
has no Android equivalent.
There’s no off
Unlike Web, Android has no off(event, callback). The only way to unsubscribe is the
Registration returned by on() — call .cancel() on it.
Suspend-function equivalents
Named with an Await suffix rather than sharing a name with an overload.
| Method | Signature |
|---|---|
initializeAwait | suspend (context: Context): Boolean |
identifyAwait | suspend (userId: String, attributes: Map<String, Any?>? = null): Boolean |
logoutAwait | suspend (): Unit |
resetAwait | suspend (): Unit |
shutdownAwait | suspend (): Unit |
There’s no trackAwait — track() is already synchronous (no I/O happens inline), so there’s
nothing to await.
Registration
fun interface Registration {
fun cancel()
}Returned by on(). Call .cancel() to stop receiving that event.
See Platform Parity for what exists on every platform.