Navigation in Jetpack Compose

Sep 10 2024 · Kotlin 1.9, Android 14, Android Studio Jellyfish

Lesson 04: Deep Linking

Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

As with previous lessons, you’ll continue to build on the movie-booking app.

composable(
  MOVIE_SELECTION_SCREEN.route,
  deepLinks = listOf(navDeepLink {
    uriPattern = "https://njc-sample-host.kodeco.com/{$MOVIE_NAME_ARG}"
    action = Intent.ACTION_VIEW
  })
) { ... }
backStackEntry.arguments?.getString(MOVIE_NAME_ARG)
@Composable
fun MovieSelectionScreen(
  modifier: Modifier = Modifier,
  onNextClick: (String) -> Unit,
  movieNameFromDeeplink: String?
) { ... }
fun MovieSelectionScreenPreview() {
  MovieSelectionScreen(onNextClick = {}, movieNameFromDeeplink = "")
}
MovieSelectionScreen(
  onNextClick = { movieName ->
    navController.navigate(
      TICKET_SELECTION_SCREEN.route.replace(
        "{$MOVIE_NAME_ARG}",
        movieName
      )
    )
  },
  movieNameFromDeeplink = backStackEntry.arguments?.getString(MOVIE_NAME_ARG)
)
<intent-filter>
  <data android:scheme="https" android:host="njc-sample-host.kodeco.com" />
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <action android:name="android.intent.action.VIEW"/>
</intent-filter>
private fun getPreSelectedMovie(
  movieNameList: List<String>,
  preselectedMovieName: String?
): String? {
  return if (movieNameList.indexOf(preselectedMovieName) >= 0) {
    preselectedMovieName
  } else {
    null
  }
}
var selectedMovieName: String? by remember {
  mutableStateOf(getPreSelectedMovie(movieNameList, movieNameFromDeeplink))
}
adb shell am start -W -a android.intent.action.VIEW -d "https://njc-sample-host.kodeco.com/The%20Dark%20Knight%20%282008%29" com.kodeco.njc.navigationcomponent
adb shell am start -W -a android.intent.action.VIEW -d "https://njc-sample-host.kodeco.com/Pulp%20Fiction%20%281994%29" com.kodeco.njc.navigationcomponent
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction Next: Conclusion