Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jetpack Navigation Component

Jetpack Navigation Component

In this deck, I have gone through the jetpack navigation component, what it is how it works, what are its different parts and how they work in harmony to make it easy to navigate in android.

Kashif Mehmood

January 04, 2022
Tweet

More Decks by Kashif Mehmood

Other Decks in Programming

Transcript

  1. About Me • Kashif Mehmood • Software Engineer • Technical

    Writer • Speaker • Opensource Contributor • Markaz (YC-W22)
  2. Fragments • Fragment represents a reusable portion of the app’s

    user interface. • Each has its own layout & lifecycle. • Cannot live on their own and must be hosted in another activity or fragment.
  3. NAVIGATION COMPONENT • Collection of tools and Libraries that simplify

    navigation • Automatically handles back stack • Type safe argument passing • Simplified deep linking • Centralizes and Visualizes Navigation
  4. PARTS OF NAVIGATION COMPONENT • Navigation graph • Nav Host

    Fragment • Nav Controller • Safe Arguments
  5. NAVIGATION GRAPH • Visualizes Navigation • Centralizes Navigation • Handles

    Actions and Destinations • Handles Fragments and Activities
  6. NAV HOST FRAGMENT • Container for the Fragments • Area

    or host within the layout for self-contained navigation to occur • A window that swaps navigation destinations on screen
  7. Destinations • Individual screens are known as Destinations, Activities/Fragments •

    Start destination is the first screen in the flow/graph.
  8. NAV CONTROLLER • NavController manages navigation within a navhost. •

    Call navigate() and it will handle the rest. • Use findNavController() to get the nav controller
  9. PASSING DATA BETWEEN FRAGMENTS Safe Args: • Gradle plugin that

    gives a much neater way to pass data. • Declare the arguments that we need to pass in nav graph. • Generates all the code you need. • Provides type safety and nullability. • Send arguments with Parcelable
  10. VIEW MODEL • Does not get destroyed on configuration changes.

    • Has its own lifecycle. • Can be used to share data between fragments. • ViewModel and ActivityViewModel.