5

Actually DetailActivity(need to pass arguments) is present in Library module and I need to launch it from app (FragmentA) but I am getting Build error as follows:

Too many arguments for public final fun actionFragmentAToDetailActivity()

I am using SafeArgs library to pass data.

FragmentA

 findNavController().navigate(
            FragmentADirections.actionFragmentAToDetailActivity(
                "id",
                "name"
            )
        )

nav_graph_app.xml (Present in app module)

<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/fragment_a_navigation"
app:startDestination="@id/fragmentA">

<fragment
    android:id="@+id/fragmentA"
    android:name="com.abhishek.fragmentA"
    android:label="WeeklyWorkListFragment"
    tools:layout="@layout/fragment_a">
    
    <action
        android:id="@+id/action_fragmentA_to_DetailActivity"
        app:destination="@id/detail_activity" />
</fragment>
</navigation>

nav_graph_common_component.xml (present in Library project which is included as a library module in build.gradle of app)

<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/common_component_navigation"

<activity
    android:id="@+id/detail_activity"
    android:name="com.components.DetailActivity"
    android:label="DetailActivity"
    tools:layout="@layout/activity_detail">
    <argument
        android:name="id"
        app:argType="string" />
    <argument
        android:name="name"
        app:argType="string" />
</activity>
</navigation>

Any help or guidance will be well appreciated.

abhishek kumar gupta
  • 2,189
  • 6
  • 35
  • 56

3 Answers3

1

You just need to add:

<include app:graph="@navigation/nav_graph_common_component" />

in your nav_graph_app.xml

Ernest Zamelczyk
  • 2,562
  • 2
  • 18
  • 32
0

FragmentA

findNavController().navigate(
                FragmentADirections.actionFragmentAToDetailActivity(
                    "id"
                ).setname("name")
            )
Saif
  • 293
  • 2
  • 9
0

1.Try using bundle with seriable

2.

val bundle = Bundle().apply {
                putSerializable("article", it)
            }
            findNavController().navigate(
                R.id.action_savedNewsFragment_to_articleNewsFragment,
                bundle
            )
  1. and In Your fragment

val args:ArticleNewsFragmentArgs by navArgs()

Manjeet deswal
  • 692
  • 2
  • 5
  • 18