Member-only story

How to make Jetpack Compose navigation easier and testable

Patryk Kosieradzki
ProAndroidDev
Published in
4 min readAug 8, 2021
Photo by Joseph Barrientos on Unsplash

Navigating in Compose is easy

Navigating in Jetpack Compose is pretty simple as you may already know. You just declare a NavHost with all your destinations and a NavHostController that will remember the navigation state and will let you controll your navigation.

For example:

We’ve just created a navController using rememberNavController() so that navigation state can survive recompositions and we declared two destinations: "firstScreen” and "secondScreen" so we can easily navigate between them.

Now to navigte from FirstScreen to SecondScreen we just use something like this:

Simple, right? But it has some drawbacks…

One last thing before we start

--

--

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Patryk Kosieradzki

Senior Android &iOS Engineer @ Moss, based in Warsaw, Poland

Responses (5)

What are your thoughts?