Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 184.108.40.206 release ready!
The interactions that allow users to travel through, into, and out of the various pieces of content within your app are referred to as navigation. The component of Android Jetpack navigation assists you in implementing navigation.
The Jetpack Navigation component depends on the below-mentioned parts:
Navigation Graph: A navigation graph is an XML resource that contains all navigation-related information in one place. This includes all of your app’s individual content areas, known as destinations, as well as the various paths a user can take through your app.NavHost: A container that is empty and displays destinations from your navigation graph. The Navigation component includes a NavHost implementation by default, NavHostFragment, which displays fragment destinations.NavController: A NavHost object that manages app navigation. As users move through your app, the NavController orchestrates the swapping of destination content in the NavHost.
As you navigate through your app, you tell the NavController that you want to navigate either along a specific path in your navigation graph or directly to a specific destination. The NavController then shows the appropriate destination in the NavHost.
The Navigation part gives various different advantages, including the mentioned below:
In your build.gradle (module-level) file
In your build.gradle (app level) file OPTIONAL for safe_args
Also, add a plugin in your module-level build.gradle file for safe args
To add a navigation graph to your project, do the following:
When you add your first navigation graph, Android Studio creates a navigation resource directory within the res directory. This directory contains your navigation graph resource file (nav_graph.xml, for example).for reference, check this screenshot
From the below code we will add a NavHostFragment
For the demo, we have added 2 fragments Fragment A and Fragment B
Here you can check that we have added some action from fragment A to Frgament B with argumnets
Here, is our Fragment A
As a result, we move to fragment B with the passed arguments.Here, is our Fragmet B
Here is our UserData data class
Note:- Please make your data class Serializable or Parcelable if you want to pass this as an argument
In the above example, you can see that we are passing some data from Fragment A to Fragment BFrom btn1:- We are just passing a string valueFor results check this screenshotFrom btn2:- We are just passing User Details with a null stringFor results check this screenshotNote: Here you can see that “EMPTY” is visible for the string argument which we have passed as a default value in our navigation graph.From btn3:- We are passing both string and User Details with this actionFor results check this screenshot
For more details, please check this link
Hopefully, this blog will be helpful to you. If you have any queries, please write them in the comment section.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.