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 22.214.171.124 release ready!
In this blog, we are going to learn Jetpack Navigation, We will clarify what is Jetpack navigation, it’s benefits, and how to use it.
It simplifies implementing navigation, while also helping you visualize your app’s navigation flow. The library provides a number of benefits, including:
The Navigation component requires Android Studio 3.3 or higher and is dependent on Java 8 language features.
The Navigation Component consists of three key parts:
Just include the following code in the dependencies block of your module-level build.gradle file.
First, we will create a file that will contain our navigation graph. In the res, directory create a new android resource file as follows.
This will create an empty resource file named nav_graph.xml under the navigation directory.
Here the root tag named navigation has a parameter called startDestination which has the id of our first fragment. This defines that the first fragment will be loaded in the NavHostFragment automatically.
The Navigation Component introduces the concept of a destination. A destination is any place you can navigate to in your app, usually a fragment or an activity.
These are supported out of the box, but you can also make your own custom destination types if needed.
Notice that for first fragment we have defined an action with the following attributes:
Each action should have a unique id which we will use to navigate to the required destination.
Here the destination points to the id of the second fragment defined in the nav graph, which means that with this action we will navigate to the second fragment.
After this step when you open the nav_graph.xml and switch to the design tab, it should look like the following.
1. Navigation using destination Id
We can provide the id of the destination fragment to navigate to it, like the following
For views, we can also use createNavigateOnClickListener() method.
3. Navigation using Actions
As in the above nav graph, we have defined action in the first fragment, we can use the id of the action as follows
Define the NavHostFragment. It is a special widget it will display the different destinations defined in the nav graph. To load the FirstFragment then copy the following code and paste it in the layout of the activity.
Jetpack another library – Android Jetpack Compose
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.
Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.