Android navigation can live in one graph instead of scattered intents
Moving from one screen to another can be as simple as an intent on a button click, until an app grows complex. Android developer and technical writer Peculiar C Umeh builds a navigation graph, a NavHost and actions from an empty Android Studio project, showing how much of the wiring the tooling writes for you. What does it take to set up Jetpack Navigation by hand and pass data between screens?
Follow a step-by-step build of a nav graph, NavHost, actions and Safe Args arguments
Android developer Peculiar C Umeh introduces the Jetpack Navigation component, explaining its navigation graph, NavHost and NavController and why it beats wiring screen changes by hand with intents. The talk then builds a navigation graph, host, fragments, actions and a typed argument live in Android Studio, and shows Safe Args passing an ID in a sample drinks app.
“It simply means moving from one screen to another.”
“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.”
What you will learn
Explain the three parts of Jetpack Navigation: the navigation graph, the NavHost and the NavController.
Create a navigation graph resource file in Android Studio and let it add the navigation dependency to the app Gradle file.
Add a NavHost to an activity layout, link it to the graph and set a start destination for a single-activity app.
Connect destinations with actions and add typed arguments in the navigation graph editor.
Use the Safe Args Gradle plugin, which generates Directions and Args classes, to pass data such as an ID between screens.
Key takeaways from the speaker
In this session, we will go through how to implement a navigation graph manually and how to navigate to different destinations. We will also look on how to pass data between destinations using safeArgs and a bit of deep linking if time permits.
Using best practice
Tools needed are Personal Computer, Install Android Studio latest version
Details
Level
Beginner
Format
Tech talk
Technical depth
Practitioner
For
Student, Early career
Length
37:53
Published
June 2021
Questions this talk answers
What is the Jetpack Navigation component?
It is a plugin 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 type-safe argument passing. It also helps set up navigation UI patterns in a simplified way.
How do you create a navigation graph manually?
Right-click the resource folder, choose New, 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 the Safe Args plugin to the Gradle file; it generates a Directions class for destinations with actions and an Args class for destinations with arguments. Arguments are added in the graph editor with an ID and a type such as string, float or boolean.
Does Jetpack Navigation work in Java or only Kotlin?
It works in both, but the speaker prefers Kotlin because the code is more concise, for example bottom navigation can be wired with one line of code.
About this talk
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 session is here to help you get a deeper understanding of the library and what it offers.
Speaker: You're welcome. Hi, good to have you around. Hi, my name is Peculiar Umeh, an Android developer. In this session, we're going to be looking at the basis of Android navigation components. I urge you to stay tuned and relax. We're going to go through a lot of things, and you're going to be looking at the basis of Android navigation components. I urge you to stay tuned and relax. We're going to go through a lot of things, and you're going to be looking at the basis of Android navigation components.
Speaker: You're going to get to understand what is Jetpack Android navigation component is, and not only what it is, and how to apply it in your mobile application. Speaker: Okay, now I'm going to be looking at different slides. Now we look at Speaker 1: It simply means moving from one screen to another. Does a user move from one screen to another? And this can be done. You can achieve it by just adding an intent to a button click in your code. And with this, you can easily move from one screen to another. Now when we looked at Jetpack navigation components, we looked at Jetpack Speaker 1: When we wanted to be more complex than just clicking just the audience. When we looked at Jetpack Speaker 1: Jetpack
Speaker 1: That's where we looked at Jetpack Speaker 1: A navigation component because it has a lot of features and a lot of things that will make it more easier for us to navigate from one screen to another. Speaker 1: And not only that Jetpack Speaker 1: Navigation component has a lot of features that will make things a lot easier for us. Now when we talk about Jetpack Speaker 1: with Jetpack navigation components, what actually are we talking about here? We know that Jetpack Speaker 1: are a plugin and a tooling for simplifying and unifying Android navigation. That's what our navigation component is all about. Now this Speaker 1: Navigation here is a lot of features that will help us that will make us consider it the best and the best for us to use in an Android navigation. Now the thing we look at here, we look at what does it offer? Why should I use it?
Speaker 1: Why should I choose to use Jetpack navigation components? Speaker 1: Number one, we need to see Speaker 1: This navigation component Speaker 1: handles backstops. It also handles transition animation. It also handles, it automates fragment transactions. Not only that, it also simplify deep linking and it also handles deep linking. Speaker 1: And it also handles the type of argument passing. I'm going to take this one after the other for us to be able to understand what they all mean.
Speaker 1: It's also set up, it's also helping setting up navigation, navigation. That's the navigation pattern. It's also help us in setting it up in a simplified way. That's why we look at it and we want. Speaker 1: We want everybody to understand how to implement it and then how to use it in your Android application. Now this Jetpack navigation component is made up of three main parts. And I'm going to look at these three main parts. We have them as the first one is navigation graph. The next one is navigation.
nav posts and the next one is nav controller that's the three main the three main parts of navigation components now I'm going to look at navigation graph what's navigation graph navigation graph is is an XML resource file it contains all the information that is information that has related to the navigation and Android in your application that's what is contained now this navigation graph also have I have an example of it I'm going to show you so that is there for us to understand if you look at what I have like this is called a navigation and when we come to our article section I'm going to show you how we can implement this manually in our Android application now this navigation graph it has a destination and it also have it has contained a lot of actions each
of these you're seeing this is a destination where you click on each of them and each of these destination is a screen on its own now you also have an action which is a route to which we navigate or we move to the next screen from one screen to another if you look at the sample I have here you have some others a lot of actions there leading us from one screen to another and there's a example of a navigation graph like I said a navigation here the navigation graph here it contains an information information about for about your application that about the whole screen from one screen to another screen and contain them and keep them in just one centralize them in just one location now the next part of the navigation
android navigation company is what we call navhost I'm going to show you example of navhost and all this we're going to implement very soon we're going to implement very soon okay now this is a sample of a navhost now this navhost is a widget a widget a widget a widget that we can add in our sml uh an sml file and this widget is responsible from one string to another string that's what it's all about I'm going to show you a sample of it by when we move into the practical section that just what is responsible for uh then the next one we have is the nav control the nav controller the nav controller is just a code that you can add into your and maybe in a fragment or in your activity that will help you to move from one screen to another this
shows an action the action you need to you have nav controller you'll find it linking it to your nav graph you'll find the action here and then this action will lead you from one screen to another the next action also can we can also achieve this uh uh uh this action we have here in this uh resource uh uh file here we can also achieve that by using a save app um plugin and how can we do that by using a save app program that's when we talk about adding data adding data in in what in a navigation now i said the save app for the navv now i said the save app plugin this is a navigation library that helps us pass data from one uh between a destination
to another destination this is a sample of a save uh uh how to pass in a data from one screen to another let's assume we have a uh a recycler view that we want to use three data that we want to use three data from a particular uh let's say from um an api now we use this same app plugin to pass in these data and we use this argument to retrieve this data from from that uh from that api so what you need to do is to what do what set up the set up the argument over here and call it in your in your fragment or in your activity so that when you click on a particular uh uh link or an a particular uh image or object it would
automatically fetch the data for that that you are looking for for that uh uh image of your click screen all right now let's go ahead to the and have the navigation destinations now this set up it has a lot this set up plugin how to use it is this you just need to add the plugin in your you just need to add a plugin the plugin in your in your gradle file you just need to add a plugin in your what in your gradle file and then same after adding it this step up plugin will automatically would generate what we generate uh uh uh uh classes for you then it will first of all generate a uh uh direction class for any action that there's any destination that needs an action then it also
it generates uh an argument class for any destination that you use an argument so that's what they say again uh the save up plugin does for you now the next one is the uh talk about the destination and i've also talked about this code you have here just what you add to your your your your fragment to your fragment or your activity for you to be able to get the action you are looking for now the next one we're going to go back to an we're going to go back to an android studio to see what we're talking about because when we talk about android development we're talking about um we will mostly look at the application of it not just uh talking about it but the application of it that's where
the ending is so i'm going to go away from this screen now and go back to my android studio where i'll come back please don't go away where i will have to implement exactly what are the few things i've explained here okay uh we'll go back again okay okay yes i'm back again now i believe you're seeing my screen over here now this there is uh there is um a project where this everything i'll be saying have been applied now in this project i see a lot of things like what i showed you you will see the same uh uh arguments here being implemented in this fragment actually the project just contain only two uh the main fragments which is this and the fragment now in the main fragment you have a lot of things
information that we need to call on the main fragment and in this fragment you already have it being called you have it being called in the main activity i think is this applied i'm going to start from the beginning to show you exactly how this is being applied okay i'm going to stop sharing that screen and then i'll move over to the next screen where we're moving into the practical section where we can exactly um apply what we are talking about because in this section we're actually looking at the implementation manually that's what we are looking at so you know how we can manually implement all this in an application okay i'm going to put up that now i'm going to put up that now i'm going to show you manually how we can implement this in our application
okay i'm going to see my screen now please if you're seeing my screen i would like you to respond just say hi to me i'm seeing your screen i'm actually appreciate you for coming just say hi over here in the chat i'm seeing your screen to show you manually how we can implement this in our application. I believe you are seeing my screen now. Please if you are seeing my screen I would like you to respond. Just say hi to me. I'm seeing your screen. I'm actually appreciative for coming. Just say hi over here in the chat. I'm seeing your screen. Then that way I will know you are with me. I appreciate you for coming in this section. Let's go ahead into the Art Drive Studio to implement this. Okay, I'm going to start
with the first thing I'm going to start with is the nav graph. Now the nav graph for me to apply the nav graph in this project which I've created. It's an empty project I just created. I just want to create a topic sample project. What I need to do is to go to the layout file. It has a layout file and then I'm going to right click on the layout file. I will go to new.
Then click on layout resources. Now I'm going to type in nav underscore graph. Then this is a file file file. I'm going to select navigation here. Sorry about that. I need to take that again. I'll be back. Okay, let me go back to take that again. I'm going to do this in the resource file because I told you that nav graph is a resource file type. So in the resource file, I'm going to click Android resource file. Then I'm going to type in nav graph. Nav graph. Then I'm going to select the type, the resource type. And the resource type is what? Navigation.
And this will automatically ask me if I will want to add this dependency in my gradle, in my app.gradle file. Now, sometimes some people will prefer to get over there, get this plugin and add it in the app.gradle file first. 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. And once I click OK, it will set and automatically add this in my dependency in my app.gradle file. We're going to check to see if that is possible. We'll wait for you to load just a few minutes. It's going to load and then we will see that. Just a few minutes. It's coming up.
Okay. As that is coming up, now you're going to see that this, this is just how we can manually implement a nav graph in our application. What did I do? I just went to resource which is over here and clicking on that it just give me some minutes. It's going to come up. Just went to resource, click on resource. I went to new and then that's not resource. Sorry about that. I clicked on resource. Right clicked on resource. I went to new and I selected Android navigation, Android resource file. Then I typed in the nav graph and selected navigation because the resource type I'm trying to add up here is navigation. Now, if you look at what you have here, you see that the nav graph has already been implemented. Over here, we don't have anything in this.
The nav graph is easy what made the jetpack navigation company. If you look at the nav graph file, you will see that this dependency has been already automatically implemented for us here in this build.gradle file. That's exactly what we have here. Okay. So, the next thing we need to do is to move ahead to I'm going to split this so you can see what we are doing at the same time.
We remove this text view because we don't need this text view. Now, I'm going to turn to design view and in the design view, what I want to implement is the next part of the navigation component, which is the nav host. Now, I'm just going to type for easy for it to be fast enough host fragment. I told you is the widget that we apply. We add in the resource file and this widget helps us is a window that helps us to swap from one screen to another screen. Now, once I I selected that, it's asking me to use this nav graph which I've already created. I'll click yes, select it and click yes. And this will automatically generate the fragment, the nav graph and add it all for me over
here. I'm going to constrain it because I'm using Constraint Layout. I prefer using Constraint Layout because that is faster for me and it doesn't waste time. I'm going to click up and down left right hand. Again, in most cases, I don't normally want to use this. So, most times, I prefer to use the main widget which is this android x fragment.app.fragment container view. I'm just going to select that and that's what I prefer to use. So, now we're done with the first thing.
Add it. The first one update, the manually added nav graph in the nav, in the nav, uh fragment, and nav graph in application. And then the next thing we did is to open the activity main, uh, main, uh, sml file and then we added what the nav ghost. What this what we added here is a nav host. And then the next thing that is meaning in this part is the nav controller which will help us to do what to call in this, to help first navigate to another. Showing all the actions. This will do inside, uh, inside, uh, main, um, fragment.
Okay. Now, because we are using fragments, we're using a single, uh, activity with different fragments. So, I would prefer to create a fragment. Uh, before I create that, I'm going to and I'm going to call this package view. Okay. Inside this package, I'm going to do what? I'm going to create. I'm going to say, let's call it first fragments. I'll click okay.
I'm going to general, general code that I might not use. So what I need to do is just to remove those code that I don't need. I'll manually add the code myself. So I could be able to manipulate and do a lot of things that I want to do. But if you look at this code already, which the, the, the fragments, you will also see the arguments here. But this argument is not really directing me to exact, to what I want exact.
So I'm going to delete them. So I'm going to delete them. So I'm going to start from here. All these, I don't need them. I want this to be clean so that I will add my own. I want this to be clean. Okay. Now I have it clean. So the next thing is to do what? So go to my Navgrad.
For a Navgrad, there must be a home. That's a starting point for every fragment, for every Android application. There must be a starting point. Now, I don't know if you have. So I'm going to call on the first fragment I have, which is the first fragment. That will be my starting point over here. Now, please, if you have a question as this session is going on, just help me type in your question in the chat area. I will be able to see it and attend to it. Okay. So far, we've been able to create just one fragment. And we're going to go ahead to create the next fragment so you can see what I've explained about the Navgrad. We are going to see a destination. Already what we have here is the destination,
which is the first fragment. And then another fragment that will help us see the action in this in the Navgrad. After that, we'll move ahead if our time permits us to add a safe app that will help us to move from one screen to another. That will help us passing data from maybe from the main fragment to the second fragment.
If time permits us to also apply deep linking in this application we're trying to set up. But if time does not permit us, okay, I'm going to drop a link below for this project, for the first project I use, so that you can go through it. If you have any questions, you can, after this conference, you can ask me through my either my GitHub or LinkedIn or Twitter and then I will be able to answer your question. I'll explain to you the parts maybe you've got you're confused about. Okay. Now let's move ahead quickly before time wraps up and we'll add the second fragment inside here and then we'll link it up.
Okay. I'll go to the next one, which is a fragment. I'll create the second fragment. I'll click okay again. It's going to also generate for me, which I don't do. But when you look at this information, we actually we actually, that's actually what we are looking at when we talk about the save up. We will see that here we have private constant valve. I'm actually using here.
Sorry, I didn't say that earlier and use actually using applying this using Kotlin, not Java. but navigation, Jetpack navigation components can also be applied in Java or in Kotlin. What differs here is this. Kotlin makes the code and everything more concise. But Java is that the code is a bit, a big and complex that you have to write in a lot of code for you to be able to achieve the same thing. Just like in Kotlin, you just a few lines arrive at what we're actually looking for when we talk about, because navigation components, we also have it when we talk about navigation UIs. When you talk about navigation UIs, we talk about bottom navigation. In bottom navigation, just one line of code can be able to navigate each screen from one,
you can be able to navigate on one icon and then bottom navigation to another icon. Just one line of code. But in Java, you'll need to write a different line of code before you can be able to do that, which will make up your code base to be, will be a lot of, a lot of code there. But Kotlin, why I prefer, and I use Kotlin because the codes are very simple, they're concise, and they're not, they're not too long, too much. You just still achieve the same, the same thing you can also achieve with Android, with Java, which you can also achieve the same thing and much more because it has a lot of other features that Java doesn't have. And it makes your work very fast, not to
spend a lot of time building just one application. Now I've also added the circle fragment. All I need to do is to do what? Over here, I'm going to click on that and you'll see that the next, that I'm going to remove this so you can see what I'm talking about here. I have the next fragment over here. What I need to do, this is a destination in the nav graph and where we are, this is nav graph. And this destination had, and we have a lot of things I can do here. I have the ID and I have the level. Then I can add the action arguments here by using the add button. I can also add in the action and then I can add the deep
links here by using the add. All of them in any one I want to add. I can just use the plus add them. So over here now, I'm going to add in an action. This action will help us to not to move from this screen to the next screen. And remember what I said that the action is a roof through with just like a bypass. If I still want to come back to the next screen, I can also draw it in and then move back to the next screen. Now, but if I don't using just code, I'm just writing code. This, I'm going to write so many code to move. I'm using intent from one button to another button. I'm going to add a button
to move from one screen to another screen. For this navigation component, I just made it very easy and very simple. By just using, looking at destination, you are going to, I'm using the action to navigate that. And this automatically generates an XML file for us. If I split now, you're going to see, let's go to split. You're going to see the XML codes that this, what action that we're taking has also generated for us. Now, let me also move over to look at how we got an argument to passing one data from different data. This will come here. Let's go back to the design view. And then, what I need to do is to click on this destination that I want to navigate to. That's this destination. I
want to move the data. When I click in on an image or any object here, I will move into the next destination. I just have to click in here. Click on that destination and then go to add. And then I have this add argument. Now, these arguments can just help me. This will also do controller can do by moving from one screen to another. Now, I'll just add an ID for that for that, for that, for that object or for that, for where I want to navigate to. I just need to add the ID.
And then I will select, is it an ID? Is it, will it be a float or a log or boolean or a string? Now, mine can be a string. Now, at this point, I may not need the default value. It's not an array. It's not, I don't need it to be a null level. And then the default value, I don't really actually need it because I'm not actually passing in any data here, but I'm just showing you how this can be done. Okay.
Once I click, I see the ID is a string and it's already applied here. And then when I split this, I'll go to the code and I will see this being navigated. I mean, what I've generated over here, you see the app type, the ID, the name, I have the ID, and then the app type is just a string.
And for me to be able to do, to navigate and to make use of it, I'm going to come back to the, let me close some of this because I don't need it. I don't need them. Okay. I need to close some of this. I don't need them for now. Okay. Thanks. Now I'm going to come to, this is my main screen.
I'm going to come here and then create a component object calling the argument here. Then the argument must have an ID. And it's this ID that I will also call it over here so that when I click on the first fragment, I will get in to the next, the second fragment with this ID, uh, with the code I've already added in the second fragment. Okay. Now, uh, my time is already up, already above before. Let me check in and see if you have questions, uh, for this. If we don't have questions, I'll believe that you are following and you've been able to, um, you were able to understand a lot of things, understood a lot of things about this and basis of Android navigation. Now I'm going to draw, uh, uh, the, the first
project I used where I showed you a sample. I'm going to bring it up again so that we can, you can look at it and then when you have questions, you feel free to ask your question and then I will be able to answer your question. Uh, after now, I'm going to remove this fragment, uh, this screen so that I will bring up the first code, uh, the first screen we use. Which is this? Okay. Just give me some minutes. That will be up. Okay.
Okay. So everything I have to explain has already been implemented here. In this project, I use data binding. I prefer using data binding and, uh, with the navigation company because it gives me, uh, it gives me, uh, less, um, uh, makes it more faster and easier for me. What I explained over there is this. This is the, the component objects I created for this app.
They have the app ID. I call it over here and the ID is a drink ID. Like, for example, I consume an API and the ID is the drink ID over here. That's what I use. Then over here in this, uh, not control. I was able to call in ID using bundle to pass in the ID over here.
And that's all I did. Then I now move over to the detail fragment because I want to get in the details of each. That's each drink. And then I just use bar ID. It's empty. This is the string is empty because I have so many drinks there so that it can pick it one after the other. Then I just make it, uh, then the legs, and then the ID, it does get the strength. Then I pass in the ID, which are the ID, the ID, which I also pass in here in my, which also have here in the, and, uh, companion object. And just with this, that's all to dot to strength. Just with this code, I've been able to achieve what I actually want to, I actually want to achieve in this application.
Okay. Now that's having been said, uh, come to the end of this session because our time is up and I'm giving you three minutes. We have gone through all this. I hope you'll see. Okay. Okay. And I want to say, uh, okay, uh, back. So I'm going through this and back to my slide again. Good. I want to say thank you to as many of you that were able to join this session. If you have any questions, you can go ahead to app, but over here, you can see the source code of the first, uh, sample I use code I used, and then you have more of the question. You can ask me in my LinkedIn or Twitter or through GitHub or mail, then I'll be able to, uh, answer your question. And I'll give you some minutes
here to drop in your question in this section. Say hi to me. So I'm running up now to say thank you very much for joining this question. I am a Claire. Thanks so much for joining this session. Thank you so much as many of you joined this section. And I also want to use this opportunity to start for sponsors from all over the continent and we are grateful. We are happy to help you and you be part of first omit this program resources. Thanks a lot. Thanks for joining this session.
Transcribed automatically; names checked against the speaker record. Select a time to jump there.
Article based on this talk
How does Android Jetpack Navigation replace hand-wired screen changes?
Peculiar C Umeh walks through the navigation graph, NavHost, NavController and Safe Args, then builds them live in Android Studio.
In short
Peculiar C Umeh, an Android developer and technical writer, argues that once an app outgrows a simple intent on a button click, the Jetpack Navigation component is the better way to move between screens. The talk explains its three parts (the navigation graph, the NavHost and the NavController), introduces the Safe Args plugin for passing data, and then builds the setup step by step in Android Studio using Kotlin.
Key takeaways
In this session, we will go through how to implement a navigation graph manually and how to navigate to different destinations. We will also look at how to pass data between destinations using Safe Args, and a bit of deep linking if time permits.
Use best practice.
Tools needed: a personal computer and the latest version of Android Studio.
Why move beyond intents
Umeh begins with the simplest definition of navigation: "It simply means moving from one screen to another." (0:29) For a basic app, adding an intent to a button click is enough. The Jetpack Navigation component becomes worthwhile when navigation gets more complex, because it brings features that would otherwise be hand-written. The speaker describes it as a plugin and tooling for simplifying and unifying Android navigation.
The list of reasons to adopt it is practical. It handles the back stack and transition animations, simplifies deep linking and supports type-safe argument passing. As Umeh puts it: "It also handles, it automates fragment transactions." (3:02) It also helps set up common navigation UI patterns, which the speaker returns to later when comparing Kotlin and Java.
The three building blocks
"Now this Jetpack navigation component is made up of three main parts." (3:40) The first is the navigation graph, an XML resource file that holds all the navigation information for the app in one central place. A graph contains destinations, each of which is a screen, and actions, which are the routes from one screen to another.
The second part is the NavHost, a widget placed in a layout file that is responsible for swapping one screen for another. The third is the NavController, the code added to a fragment or activity that looks up an action in the graph and performs the move. Together they replace the scattered intent code that would otherwise live behind every button.
Passing data with Safe Args
For sending data between destinations, Umeh introduces the Safe Args plugin. Once it is added to the Gradle file, it generates classes automatically: a Directions class for any destination that has an action, and an Args class for any destination that takes an argument. The example given is a list of items loaded from an API, where tapping one item opens a screen that fetches the details for that item.
Later in the demo, the speaker adds an argument in the graph editor: select the destination, add an argument, give it an ID and pick its type (string, float, long, boolean and so on), with optional default value and nullability. "Once I click, I see the ID is a string and it's already applied here." (31:51) Switching to the split view shows the XML that the editor wrote.
Building it by hand in Android Studio
The practical section starts from an empty project. To create the graph, Umeh right-clicks the resource folder, chooses New and Android Resource File, names it nav_graph and selects Navigation as the resource type. Android Studio then offers to add the navigation dependency itself: "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." (16:23)
Next comes the NavHost. In the main activity layout, the default text view is removed and a NavHost fragment is added in design view and linked to the graph. Umeh constrains it with ConstraintLayout and notes a personal preference for the AndroidX FragmentContainerView widget. The app follows a single-activity approach with several fragments, so the speaker creates a view package, adds a first fragment, strips out the generated boilerplate and sets it as the home of the graph: "That's a starting point for every fragment, for every Android application. There must be a starting point." (23:35)
Kotlin, actions and a working sample
While adding a second fragment, Umeh pauses to explain the choice of language. Navigation works in Java or Kotlin, but "Kotlin makes the code and everything more concise." (26:31) The speaker's example is bottom navigation, which can be wired with one line of code in Kotlin but takes more code in Java.
With two destinations in place, an action is drawn between them in the graph editor, replacing the button-and-intent code that would otherwise be needed. "And this automatically generates an XML file for us." (29:57)
To close, Umeh returns to a finished sample, a drinks app built on an API. "In this project, I use data binding." (34:22) A companion object holds the argument key, the NavController passes the drink ID in a bundle, and the detail fragment reads that ID to show the right drink. Deep linking, listed as a stretch goal, was not covered for lack of time; the speaker shared the sample's source code and invited questions through GitHub, LinkedIn, Twitter or email.
Watch the talk
"Basics of Android Jetpack Navigation Components" by Peculiar C Umeh (38 minutes): https://www.womentech.net/video/basics-android-jetpack-navigation-components
About the speaker
Peculiar C Umeh is an Android developer, open-source lover and technical writer based in Nigeria. Umeh's work brings together Android development, open source and writing about technology for other developers.
Questions this talk answers
What is the Jetpack Navigation component?
Why use Jetpack Navigation instead of intents on button clicks?
How do you create a navigation graph manually?
How do you pass data between destinations?
Does Jetpack Navigation work in Java or only Kotlin?
Drafted with AI from the talk transcript. Editor review pending.
Frameworks and ideas mentioned
Single-activity architecture
Resources mentioned
Android Studio (latest version)
Safe Args Gradle plugin
Speaker's sample project source code (shared via GitHub)
Cite this talk
Peculiar C Umeh. "Basics of Android Jetpack Navigation Components." WomenTech Network, 2021. https://www.womentech.net/video/basics-android-jetpack-navigation-components