Kotlin·Kotlin from syntax to a coroutine app

Android with Compose

Build a small screen with composable functions and state.

Beginner 14 min read Lesson 7 of 300 Challenge included
What you will be able to do
  • Use @Composable functions for UI.
  • Use remember { mutableStateOf(...) } for state.
  • Hoist state to the caller for reuse.
  • Preview components in Android Studio.

In plain English

Jetpack Compose describes UI with functions. State drives recomposition: remember and mutableStateOf hold local state, and state hoisting keeps components reusable.

Counter.ktKotlin
@Composable
fun Counter() {
    var count by remember { mutableStateOf(0) }
    Column(modifier = Modifier.padding(16.dp)) {
        Text("Clicked $count times")
        Button(onClick = { count += 1 }) {
            Text("Increment")
        }
    }
}
Your turn

Hold local state

Easy

Create a remembered mutable state for a counter.

KOTLIN · starter
var count =
Check your understanding before moving on.
Knowledge checkQuestion 1

What triggers recomposition in Compose?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Testing
Lesson 7 of 300 · 0% of course