When using Navigation Architecture Components and when launching fragment from the navigation drawer you use Menu and navigation graph where for example the menu below which is for navigation drawer called "drawer_menu"
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/home_group"
android:checkableBehavior="all">
<item
android:id="@id/nav_fetch_fragment"
android:icon="@drawable/ic_fetch"
android:title="@string/Fetch" />
</group>
</menu>
And Below the respective navigation graph
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation_graph"
app:startDestination="@id/nav_splash_fragment">
<fragment
android:id="@+id/nav_splash_fragment"
android:name="manu.apps.movieapp.fragments.SplashFragment"
android:label="Splash"
tools:layout="@layout/splash_fragment">
</fragment>
<fragment
android:id="@+id/nav_home_fragment"
android:name="manu.apps.movieapp.fragments.HomeFragment"
android:label="Home"
tools:layout="@layout/home_fragment">
<action
android:id="@+id/action_home_to_fetch_fragment"
app:destination="@id/nav_fetch_fragment"
app:enterAnim="@anim/anim_slide_in_right"
app:exitAnim="@anim/anim_slide_out_left"
app:popEnterAnim="@anim/anim_slide_in_left"
app:popExitAnim="@anim/anim_slide_out_right">
<argument
android:name="fetchType"
android:defaultValue="fetchClients"
app:argType="string" />
</action>
</fragment>
<fragment
android:id="@+id/nav_fetch_fragment"
android:name="manu.apps.movieapp.fragments.FetchFragment"
android:label="Fetch"
tools:layout="@layout/fetch_fragment">
<argument
android:name="fetchType"
android:defaultValue="fetchAdmin"
app:argType="string"/>
</fragment>
</navigation>
By doing this you just set up below code and when you click on Fetch in the navigation drawer it will open the fragment automatically without any extra code
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
navigationView navigationView = findViewById(R.id.navigation_view);
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
AppBaronfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.nav_home_fragment, R.id.nav_fetch_fragment)
.setOpenableLayout(drawerLayout)
.build();
NavigationUI.setupWithNavController(navController, appBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
The problem i am having is in the "nav_fetch_fragment" argument in navigation graph where everytime i launch the fragment from Navigation Drawer it passes the default value "fetchAdmin" but i have 3 different types of fetching which i would like for them to be parsed differently whenever i click on the navigation drawer. My Fetch Types include "fetchClient", "fetchCustomer", "fetchAdmin" which should load different recycler views data when clicked from the navigation drawer.
How can i go about doing this because normally you would just declare Navigation Directions from the fragment you are navigating from to the fragment you are navigating to, for example below navigating from home fragment to fetch fragment
HomeFragmentDirections.ActionHomeToFetchFragment actionHomeToFetchFragment =
HomeFragmentDirections.actionHomeToFetchFragment ();
actionHomeToFetchFragment.setFetchType("fetchCustomers);
Navigation.findNavController(view).navigate(actionHomeToFetchFragment);