Your Second Kotlin Android App

Aug 29 2023 · Kotlin 1.8.21, Android 13, Android Studio Flamingo | 2022.2.1

Part 4: Use Jetpack Navigation

26. Setup Jetpack Compose Navigation

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 25. Learn Single Activity Architecture Next episode: 27. Create a NavHost

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 26. Setup Jetpack Compose Navigation

In this episode, you’ll be setting up the Jetpack Compose navigation library to handle navigation with your app.

To start, you’ll need to add the Jetpack Compose navigation library to your project.

Add the following dependency to your app-level build.gradle file:

implementation "androidx.navigation:navigation-compose:2.5.3"

Do a gradle sync to download the dependency to your project.

Next, you’ll create a sealed class to represent the screens in your app. This class will be used to define the navigation graph for your app.

Create a new package named navigation and add a new file named Screens.kt to it.

Add the following code to the file:

sealed class Screens(val route: String) {
    object TaskListScreen : Screens("taskList")
    object TaskDetailScreen : Screens("taskDetail")
}

In the code above, you’re defining two screens in your app: TaskListScreen and TaskDetailScreen. Each screen has a route property that represents the route to the screen. The route is used to define the navigation graph for your app.

Your setup is ready! In the next episode, you’ll define the navigation graph for your app.