Kotlin for Android

Jetpack Compose UI, state, and how an Android app is structured.

Android is where most Kotlin is written. Modern Android UIs are built with Jetpack Compose: the screen is a Kotlin function of its state, and changing the state automatically redraws what changed.

App structure

Doing network or file work directly in a composable or on the main thread

Load data in a ViewModel with coroutines on Dispatchers.IO and expose it as state

Blocking the main thread freezes the UI and Android eventually shows an 'App not responding' dialog.

What causes a composable to redraw?

A change to state it reads (e.g. a mutableStateOf value or a collected Flow); Compose recomposes only the functions that read the changed state.