What is Jetpack Compose?
A new way to build UI
For over a decade, Android screens were built in XML layout files, then wired up in code with findViewById and manual updates. Jetpack Compose replaces all of that. Instead of describing a static layout and then mutating it, you write Kotlin functions that describe the UI for the current state. When the state changes, Compose automatically redraws the parts that need updating.
Imperative vs declarative
Understanding this shift is the key to Compose:
- Old (imperative): “Find the TextView, then set its text to the new value.” You manage every change by hand.
- New (declarative): “This Text shows this value.” You describe the result, and Compose figures out the changes.
This means less code, fewer bugs (no forgotten UI updates), and screens that always match your data.
Your first composable
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@Composable
fun Greeting(name: String) {
Text(text = "Hello, $name!")
}
The @Composable annotation marks a function that describes UI. Composables can call other composables, so you build a whole screen by combining small pieces.
Showing it on screen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Greeting("Android")
}
}
}
}
Notice there is no XML and no setContentView with a layout id — setContent { } takes composable code directly.
Why Compose is the future
- Far less boilerplate — no XML, no View Binding, no adapters for lists.
- Reusable, testable UI pieces (just functions).
- Powerful animations and theming built in.
- Now also runs on iOS, desktop and web via Compose Multiplatform.
Common beginner mistakes
- Trying to “update” a composable manually like an old View — instead, change the state and let it recompose.
- Forgetting the
@Composableannotation. - Mixing XML thinking with Compose — let go of
findViewById.
Summary: Compose is declarative: you write Kotlin functions that describe the UI for the current state, and Compose redraws automatically when the state changes. This is simpler and safer than the old XML + findViewById approach.