07
Languages / Intermediate

Kotlin and Android fundamentals

Kotlin syntax, null safety, coroutines, Android architecture, state, storage, networking, and lifecycle-aware code.

kotlinandroidcoroutinesviewmodelroom

01Kotlin strengths

Kotlin reduces boilerplate with data classes, null safety, extension functions, sealed classes, and coroutines. On Android, lifecycle-aware architecture prevents work from being tied directly to fragile Activity/Fragment instances.

kotlinImmutable data + collection operators
data class Device(
    val id: String,
    val name: String,
    val online: Boolean
)

fun onlineNames(devices: List<Device>): List<String> =
    devices.filter { it.online }.map { it.name }

02Android application layers

  • UI: Compose or Views renders state and sends user intents.
  • ViewModel: owns screen state and coordinates use cases.
  • Repository: abstracts local/database/network data sources.
  • Data sources: Room, files, DataStore, HTTP/WebSocket/LAN clients.

03Structured concurrency

kotlinLifecycle-aware coroutine
viewModelScope.launch {
    runCatching { repository.refreshDevices() }
        .onSuccess { devices -> state.value = UiState.Ready(devices) }
        .onFailure { error -> state.value = UiState.Error(error.message ?: "Failed") }
}