Illegalargumentexception: Navigation Destination Xxx Is Unknown to This Navcontroller

Navigation destination is unknown to this NavController?

You declare an action just for navigating from HomeFragment to SettingsFragment. This action can only be used with HomeFragment as a starting point, so for other Fragments you get the Exception "{actionId} is unknown to this NavController".

Since you need to navigate to SettingsFragment from several starting points, you can declare a global action

<action android:id="@+id/action_global_settingsFragment"
app:destination="@id/settingsFragment"/>

IllegalArgumentException: Navigation action/destination cannot be found from the current destination Destination [Navigation Error]

You need to add only JobsFragment in your nav graph and add action in this fragment for PrivsDetailFragment.

<fragment
android:id="@+id/jobsFragment"
android:name="com.gazelle.wadifatk.jobLists.jobsFragment"
android:label="الوظائف"
tools:layout="@layout/fragment_jobs" >
<action
android:id="@+id/action_jobsFragment_to_govSectionFragment"
app:destination="@id/govSectionFragment" />
<action
android:id="@+id/action_jobsFragment_to_latestNewsFragment"
app:destination="@id/latestNewsFragment" />
<action
android:id="@+id/action_jobsFragment_to_privsDetailFragment"
app:destination="@id/privsDetailFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim" />
</fragment>

And then in you adapter, using this action:

PushDownAnim.setPushDownAnimTo(holder.card_view)
//.setScale(PushDownAnim.MODE_SCALE, 0.89f)
.setOnClickListener {
val sendData = JobFragmentDirections.actionJobFragmentToPrivsDetailFragment(priv_list[position])
Navigation.findNavController(view).navigate(sendData)
}

You can remove privSectionFragment from the nav graph.

Avoiding Android navigation IllegalArgumentException in NavController

You can use the below code before navigating to check whether the current destination is correct or not. This will make sure that the call happens from the current fragment only. This issue can be reproduced by clicking on two views simultaneously(Two items in a list).

if (findNavController().currentDestination?.id == R.id.currentFragment) {
findNavController().navigate(R.id.action_current_next)
}


Related Topics



Leave a reply



Submit