Changes

An Android Navigation Component Tutorial

237 bytes removed, 18:48, 16 January 2019
Declaring a Navigation Host
After adding the navigation dependencies to the file, click on the Sync Now link to resynchronize the build configuration for the project.
== Creating Creating the Navigation Graph Resource File ==
With the navigation libraries added to the build configuration the navigation graph resource file can now be added to the project. As outlined in [[An Overview of the Android Jetpack Navigation Architecture Component]], this is an XML file that contains the fragments and activities through which the user will be able to navigate, together with the actions to perform the transitions and any data to be passed between destinations.
Within the Project tool window, locate the res folder (app -> res), right-click on it and select the New ->Android Resource File menu option:
Before adding any destinations to the navigation graph, the next step is to add a navigation host fragment to the project.
== Declaring Declaring a Navigation Host ==
For this project, the navigation host fragment will be contained within the user interface layout of the main activity. This means that the destination fragments within the navigation graph will appear in the content area of the main activity currently occupied by the main_fragment.xml layout. Locate the main activity layout file in the Project tool window (app -> res -> layout -> main_activity.xml) and load it into the layout editor tool.
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, MainFragment.newInstance())
                .commitNow();
    }
}
</pre>
[[File:as_3.2_navigation_navhost_added.png]]
 
== Adding Navigation Destinations ==