Skip to content

Getting LUNA ID status after initialization#

This topic applies to LUNA ID for Android only.

This topic provides an instruction how to use StateFlow to track LUNA ID initialization status.

1․ Prepare the environment. Make sure you are in a ViewModel or CoroutineScope context to use coroutines and StateFlow.

2․ Launch the coroutine using viewModelScope.launch to start collecting engine initialization status changes.

viewModelScope.launch {
engineInitStatus.collect { status ->
// Handle each initialization status change
}
}

3․ Handle the statuses. Use the when construct to handle different initialization statuses. Depending on the current status, perform appropriate actions.

when (status) {
EngineInitStatus.NotInitialized -> {
// Actions before initialization
}
EngineInitStatus.InProgress -> {
// Actions during initialization
}
EngineInitStatus.Success -> {
// Actions after initialization is complete
}
EngineInitStatus.Failure -> {
// Actions if initialization fails
}
}

4․ Use StateFlow. engineInitStatus is a StateFlow object that stores the current initialization state of the engine. This allows you to subscribe to status changes and get the latest state at any time after activation.
StateFlow ensures that all subscribers always get the latest state value, even if they subscribed after a change. This makes it a convenient tool for tracking states in your app.