New

🧭 Jetpack Compose Navigation 3 Tutorial for Beginners

Build a three-screen Study Notes app with Navigation 3: type-safe keys, a back stack you own, arguments, saved state and a ViewModel per screen.

Beginner ⏱️ ~35 minutes 🧰 Kotlin, Jetpack Compose, Navigation 3 1.2.2
← Android Track

What You'll Build in This Navigation 3 Tutorial

This Jetpack Compose Navigation 3 tutorial builds a small Study Notes app with three screens: a note list, a note detail screen that receives a note ID, and a settings screen. Along the way you will learn the big idea behind Navigation 3: the back stack is just a list that you own. You add a key to navigate forward and remove one to go back, and NavDisplay shows whatever is on top.

Navigation 3 is Google's newer navigation library built for Compose. Unlike Navigation Compose (Navigation 2), there is no NavController and no route strings. If you followed the Navigation topic in our Android track, this page is the modern version of that lesson.

Prerequisites

  • Basic Kotlin and Jetpack Compose: composables, remember and state. Our Compose state management guide covers this.
  • Android Studio with a new Empty Activity (Compose) project.
  • compileSdk 36 or higher, which the Navigation 3 setup guide requires.
  • An emulator or phone to run on. If Run fails with "No target device found", see our fix guide.

Build the App with Navigation 3 Step by Step

1 Add the Navigation 3 dependencies

Add these entries to gradle/libs.versions.toml. The versions are the latest stable ones listed on Google's release pages on November 21, 2026 (Navigation 3 1.2.2 and Lifecycle 2.11.1). Set the serialization plugin to the same version as your project's Kotlin plugin.

[versions]
nav3Core = "1.2.2"
lifecycle = "2.11.1"
kotlinxSerializationCore = "1.9.0"
kotlinSerialization = "2.2.21" # use your project's Kotlin version

[libraries]
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "nav3Core" }
androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "nav3Core" }
androidx-lifecycle-viewmodel-navigation3 = { module = "androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "lifecycle" }
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerializationCore" }

[plugins]
jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinSerialization" }

Then apply the plugin and add the libraries in app/build.gradle.kts, and sync:

plugins {
    // ...existing plugins
    alias(libs.plugins.jetbrains.kotlin.serialization)
}

dependencies {
    // ...existing dependencies
    implementation(libs.androidx.navigation3.runtime)
    implementation(libs.androidx.navigation3.ui)
    implementation(libs.androidx.lifecycle.viewmodel.navigation3)
    implementation(libs.androidx.lifecycle.viewmodel.compose)
    implementation(libs.kotlinx.serialization.core)
}

2 Define a key for each screen

In Navigation 3 every screen is identified by a key: an ordinary Kotlin object or data class. Arguments are simply properties of the key, so they are type-safe for free. Keys implement NavKey and are marked @Serializable so the back stack can be saved when the app is rotated or put in the background.

import androidx.navigation3.runtime.NavKey
import kotlinx.serialization.Serializable

@Serializable
data object NoteList : NavKey

@Serializable
data class NoteDetail(val noteId: Int) : NavKey

@Serializable
data object Settings : NavKey

data class Note(val id: Int, val title: String, val body: String)

val sampleNotes = listOf(
    Note(1, "Kotlin basics", "val is read-only, var can change."),
    Note(2, "Compose state", "remember keeps a value across recompositions."),
    Note(3, "Navigation 3", "The back stack is just a list you own.")
)

3 Create the back stack and NavDisplay

rememberNavBackStack(NoteList) creates a saveable back stack that starts on the list screen. NavDisplay watches it and shows the top entry. The entryProvider DSL maps each key type to its screen with entry<Key> { }; for keys with arguments, the lambda receives the key.

import androidx.compose.runtime.Composable
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.rememberNavBackStack
import androidx.navigation3.ui.NavDisplay

@Composable
fun StudyNotesApp() {
    val backStack = rememberNavBackStack(NoteList)

    NavDisplay(
        backStack = backStack,
        onBack = { backStack.removeLastOrNull() },
        entryProvider = entryProvider {
            entry<NoteList> {
                NoteListScreen(
                    notes = sampleNotes,
                    onNoteClick = { id -> backStack.add(NoteDetail(id)) },
                    onSettingsClick = { backStack.add(Settings) }
                )
            }
            entry<NoteDetail> { key ->
                NoteDetailScreen(
                    note = sampleNotes.first { it.id == key.noteId },
                    onBack = { backStack.removeLastOrNull() }
                )
            }
            entry<Settings> {
                SettingsScreen(onBack = { backStack.removeLastOrNull() })
            }
        }
    )
}

Notice there is no navigate("details/$id"). Navigating forward is backStack.add(...) and going back is backStack.removeLastOrNull(). The system back gesture calls onBack, which does the same thing.

4 Write the three screens

The screens are plain composables. They never see the back stack; they only receive data and callbacks, which keeps them easy to preview and test.

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun NoteListScreen(
    notes: List<Note>,
    onNoteClick: (Int) -> Unit,
    onSettingsClick: () -> Unit
) {
    Column(Modifier.fillMaxSize().safeDrawingPadding().padding(16.dp)) {
        Text("Study Notes", style = MaterialTheme.typography.headlineMedium)
        Spacer(Modifier.height(12.dp))
        LazyColumn(Modifier.weight(1f)) {
            items(notes, key = { it.id }) { note ->
                Text(
                    text = note.title,
                    style = MaterialTheme.typography.titleMedium,
                    modifier = Modifier
                        .fillMaxWidth()
                        .clickable { onNoteClick(note.id) }
                        .padding(vertical = 12.dp)
                )
                HorizontalDivider()
            }
        }
        Button(onClick = onSettingsClick) { Text("Settings") }
    }
}

@Composable
fun NoteDetailScreen(note: Note, onBack: () -> Unit) {
    // Saved per entry: kept while this screen is on the back stack
    var reviewed by rememberSaveable { mutableIntStateOf(0) }

    Column(Modifier.fillMaxSize().safeDrawingPadding().padding(16.dp)) {
        Text(note.title, style = MaterialTheme.typography.headlineMedium)
        Spacer(Modifier.height(8.dp))
        Text(note.body)
        Spacer(Modifier.height(16.dp))
        Button(onClick = { reviewed++ }) { Text("Mark reviewed ($reviewed)") }
        TextButton(onClick = onBack) { Text("Back to list") }
    }
}

@Composable
fun SettingsScreen(onBack: () -> Unit) {
    Column(Modifier.fillMaxSize().safeDrawingPadding().padding(16.dp)) {
        Text("Settings", style = MaterialTheme.typography.headlineMedium)
        Spacer(Modifier.height(8.dp))
        Text("Nothing to configure yet.")
        TextButton(onClick = onBack) { Text("Back") }
    }
}

Finally, call StudyNotesApp() from MainActivity:

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme { StudyNotesApp() }
        }
    }
}

Run the app, open a note, tap Mark reviewed a few times, then rotate the device. The count survives because the default entry decorator saves rememberSaveable state for each entry. Press back and open the note again: the count resets, because that entry left the back stack and its state was cleared.

5 Give each screen its own ViewModel

By default, a viewModel() call is scoped to the Activity, so every note would share one ViewModel. Add the ViewModel store decorator from lifecycle-viewmodel-navigation3 and each entry gets its own ViewModel, cleared when the entry is popped. When you pass entryDecorators yourself, keep the saveable state decorator first, as Google's docs show.

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator

class ReviewViewModel : ViewModel() {
    var reviews by mutableIntStateOf(0)
        private set

    fun review() { reviews++ }
}

// Inside StudyNotesApp()
NavDisplay(
    backStack = backStack,
    onBack = { backStack.removeLastOrNull() },
    entryDecorators = listOf(
        rememberSaveableStateHolderNavEntryDecorator(),
        rememberViewModelStoreNavEntryDecorator()
    ),
    entryProvider = entryProvider {
        // ...NoteList and Settings entries as before
        entry<NoteDetail> { key ->
            val vm: ReviewViewModel = viewModel()
            // one ReviewViewModel per NoteDetail entry
            NoteDetailScreen(
                note = sampleNotes.first { it.id == key.noteId },
                onBack = { backStack.removeLastOrNull() }
            )
        }
    }
)

To use it, change NoteDetailScreen to take reviews: Int and onReview: () -> Unit instead of its own counter, and pass vm.reviews and vm::review. That is the first practice task below.

6 Navigation 3 vs Navigation 2 in one minute

  • Destinations: Navigation 2 uses route strings or route classes inside a NavHost graph; Navigation 3 uses keys in an entryProvider.
  • Who owns the back stack: in Navigation 2 the NavController does; in Navigation 3 you do, as a normal list.
  • Navigating: navController.navigate(...) becomes backStack.add(...); popBackStack() becomes removeLastOrNull().
  • Arguments: no arguments?.getString(); read properties straight from the key.

Navigation 2 is still supported, so you do not have to migrate an existing app today. Google publishes a step-by-step migration guide when you are ready.

Practice Task

Extend the Study Notes app on your own, then check yourself with the quiz below.

  1. Wire ReviewViewModel into NoteDetailScreen as described in step 5 and confirm each note keeps its own count while it is on the back stack.
  2. Add an EditNote(val noteId: Int) key and screen that opens from the detail screen.
  3. Add a "Home" button on the edit screen that removes everything above NoteList (hint: while (backStack.size > 1) backStack.removeLastOrNull()).
  4. Show a "Note not found" screen instead of crashing when sampleNotes has no matching ID (use firstOrNull).

Navigation 3 Tutorial Quiz

Five quick questions on this tutorial.

Frequently Asked Questions

What is Navigation 3 in Jetpack Compose?

Navigation 3 is a Jetpack navigation library built for Compose. You keep the back stack as a list of keys that you own, and NavDisplay shows the entry for the key on top.

Is Navigation 3 stable?

Yes. Google's release page lists 1.2.2 as the latest stable version of androidx.navigation3 as of November 18, 2026, with 1.3.0 in alpha.

How do I pass arguments in Navigation 3?

Make the key a data class with the arguments as properties, such as NoteDetail(val noteId: Int), add it to the back stack, and read key.noteId inside entry<NoteDetail>.

Do I need kotlinx serialization for Navigation 3?

If you use rememberNavBackStack, your keys must implement NavKey and be @Serializable so the back stack can be saved, so you add the Kotlin serialization plugin and kotlinx-serialization-core.

Should I migrate from Navigation Compose to Navigation 3?

Not urgently. Navigation 2 is still supported. Navigation 3 is a good choice for new Compose apps, and Google provides a migration guide for existing ones.

Sources

APIs and versions checked against the official Android Developers documentation on November 21, 2026 (Navigation 3 1.2.2, Lifecycle 2.11.1). Google's setup page pins the lifecycle-viewmodel-navigation3 alpha; the stable 2.11.1 is used here.

What to Try Next

Keep learning Android

Head back to the Android with Kotlin track for the full learning path and more hands-on projects.

Back to the Android Track