0:0037:54

Basics of Android Navigation Components

Peculiar C Umeh 37:54 2021

Most Android developers never harness the full power of Jetpack Navigation

Moving between screens with an intent on a button click works until an app gets more complex, and then back stacks, animations, fragment transactions and deep links pile up. Android developer and PeTECH In. founder Peculiar C Umeh builds a navigation graph live in Android Studio to show how much of that work the Jetpack Navigation component takes over. Which pieces do you actually need to wire together?

See how to build a nav graph, add a NavHost and pass arguments between fragments in Kotlin

Watch on YouTube

In short

Peculiar C Umeh introduces the Android Jetpack Navigation component, explaining why it beats wiring intents to button clicks and how its three parts (navigation graph, NavHost and NavController) fit together. The talk then builds a nav graph, NavHost, actions and typed arguments live in Android Studio with Kotlin, and closes with a sample app that passes IDs between fragments.

“But you might not need to do that because once you want to generate your nav graph, it will ask you if you need this dependency in your app.gradle file.”
“That's a starting point for every fragment, for every Android application. There must be a starting point.”

What you will learn

  • Explain the roles of the navigation graph, the NavHost and the NavController in Jetpack Navigation.
  • Create a navigation graph resource in Android Studio and let it add the navigation dependency for you.
  • Add a NavHost to an activity layout and set a start destination for a single-activity app.
  • Define actions and typed arguments in the graph editor to move and pass data between fragments.
  • Weigh Kotlin against Java for navigation code, including one-line bottom navigation setup.

Key takeaways from the speaker

  • Jetpack Navigation library.
  • Using best practice

Details

Level
Beginner
Format
Tech talk
Technical depth
Practitioner
For
Student, Early career
Length
37:54
Published
June 2021

Questions this talk answers

What is the Jetpack Navigation component?

It is a set of plugins and tooling for simplifying and unifying Android navigation. It is made up of three main parts: the navigation graph, the NavHost and the NavController.

Why use Jetpack Navigation instead of intents on button clicks?

It handles the back stack and transition animations, automates fragment transactions, simplifies deep linking and handles argument passing. It also helps set up navigation UI patterns such as bottom navigation.

How do you create a navigation graph in Android Studio?

Right-click the resource folder, choose New and Android resource file, name it nav_graph and select Navigation as the resource type. Android Studio then offers to add the navigation dependency to the app Gradle file.

How do you pass data between destinations?

Add an argument to the target destination in the graph editor and choose its type, such as a string. The Safe Args plugin generates Directions and Args classes, and in the speaker's sample an ID is passed to a detail fragment.

Should you use Kotlin or Java with Jetpack Navigation?

Both work, but the speaker prefers Kotlin because the code is more concise. Bottom navigation, for example, can be wired with one line of Kotlin while Java needs more code.

About this talk

The jetpack navigation library was created to provide a better user experience with navigation. However, most developers do not know how to harness the full power of the library. This topic is here to help you get a deeper understanding of the library and what it offers.

Topics

Related talks

Browse the library

Why Jetpack Compose?

Miriana Itani Android Team Lead

A Compose counter that never counts, and what it teaches about state

Intermediate Software engineering and cloud 2022