setContent: Where Your UI Begins
Hook your Composable tree into the Activity.
setContent: Where Your UI Begins is a free Jetpack Compose Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Connecting Compose to Android
Your Composables need a home. The setContent call inside an Activity is the bridge that hands your UI tree to the Android screen. 🔗
Inside onCreate
You call setContent from an Activity onCreate. That is the moment Android tells your app it is time to show a screen.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { Greeting() }
}It Takes a Lambda
setContent accepts a lambda, and inside that block you call your Composables. Everything in the braces becomes the screen content.
setContent {
Greeting("Compose")
}The Lambda Is Composable
That lambda is itself a @Composable scope. So you can call any Composable directly inside it, no extra setup required.
One Root Composable
A clean app calls a single root Composable here, often your whole app or theme, which then nests everything else below it.
setContent {
MyApp()
}Wrap in Your Theme
Most apps wrap the root in their theme so colors and fonts apply everywhere. The theme is just another Composable around your UI.
setContent {
MyAppTheme {
MyApp()
}
}Replaces setContentView
In the old View system you called setContentView with an XML layout. Compose swaps that for setContent with a Composable lambda.
Extends ComponentActivity
The Activity that uses setContent typically extends ComponentActivity, the lightweight base class Compose is designed to work with.
class MainActivity : ComponentActivity() {
// onCreate with setContent
}Where the Tree Mounts
setContent is the entry point. From here Compose builds, lays out, and draws the whole tree of Composables you call inside it.
Add Surface for Background
Wrapping content in a Surface gives a themed background and elevation, a common first child under your theme.
setContent {
MyAppTheme {
Surface { MyApp() }
}
}One setContent Per Screen
You normally call setContent once per Activity. To show different content, you change state inside the tree, not call setContent again.
Quick Check
A final check on where Compose UI starts.
Recap
You now know where it all begins: call setContent in onCreate, pass a Composable lambda, wrap it in your theme, and Compose draws your app. 🎉
Frequently asked questions
Is the “setContent: Where Your UI Begins” lesson free?
Yes — the full text of “setContent: Where Your UI Begins” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.
What will I learn in “setContent: Where Your UI Begins”?
Hook your Composable tree into the Activity. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Jetpack Compose Academy?
No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “setContent: Where Your UI Begins” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Jetpack Compose Academy lesson?
Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Writing a @Composable Function
- Live Previews with @Preview
- Calling Composables from Composables
- setContent: Where Your UI Begins