Jetpack Navigation: Getting Started

Aug 10 2021 · Kotlin 1.4, Android 11, Android Studio 4.2.1

Part 1: Set Up Navigation

01. Jetpack Navigation Overview

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Next episode: 02. Understand the Project Structure

Notes: 01. Jetpack Navigation Overview

Basic knowledge of Android and Kotlin required to follow the concepts and code. You will require Android Studio 3.3 or higher to add the Navigation component. If you need to download a recent version of Android Studio, you can do so here.

Transcript: 01. Jetpack Navigation Overview

Navigation refers to the interactions that allow users to navigate across, into, and back from the different screens within your app.

Traditionally, developers used do this using intents or fragment transactions. That served the purpose for simple cases like button clicks, but what if you want to handle more complex scenarios like navigating to an intermediate screen within the app from Push Notification.

In this case, you have to also handle back navigation manually so that users don’t just exit the app on pressing back button.

To solve several such problems faced by developers in Implementing a complex navigation in Android Apps, Android team at Google Introduced Navigation Architecture component which is a part of Android Jetpack.

Navigation Architecture component is a framework for navigating within your app. Aprt from libraries, it also provides tools and guidance for simplifying and unifying in-app navigation.

Navigation architecture component automates fragment transactions, handles back stack , simplifies set up for common navigation patterns such as Navigation drawers and Bottom navigation.

It also supports transition animations, type safe argument passing using a gradle plugin called Safe Args. It handles Deep links - both Explicit and Implicit.

Most important and interesting part is that it gathers all navigation related information and puts it at a centralised location Called Navigation Graph.

Navigation graph is one of the three key parts of Navigation architecture component. The other two are NavHost and NavController.

Navigation graph is an XML resource that contains all navigation related information. Navigation graph can be visualised in Navigation Editor which is available in Android Studio 3.3 or higher.

Inside the navigation graph, each individual content area is called Destination. These destinations are connected via Actions, and are represented via Arrows in the Graph.

NavHost is a container that displays destinations from your navigation graph. It swaps different destinations IN and OUT as user navigates within your app.

If you are building App with Single Activity - Multiple fragments, your NavHost will be NavHostFragment that displays fragment destinations.

NavController is an an object that manages app navigation within a NavHost. For Navigation, you tell the NavController, where you want to Navigate to. NavController then shows your Desired destination in the NavHost.

Navigation component has built in support for Activities and Fragments as Destination types and can be extended to work with custom destinations like dialog fragments and custom views.

Enough of theory, isn’t it! Let’s go to Android Studio and Begin Navigation in Action in next episode!