实际上 DetailActivity(需要传递参数)存在于库模块中,我需要从应用程序(FragmentA)启动它,但我收到如下构建错误:
Too many arguments for public final fun actionFragmentAToDetailActivity()
我正在使用 SafeArgs 库来传递数据。
片段A
findNavController().navigate(
FragmentADirections.actionFragmentAToDetailActivity(
"id",
"name"
)
)
nav_graph_app.xml(存在于应用模块中)
<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(存在于库项目中,作为库模块包含在 app 的 build.gradle 中)
<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>
任何帮助或指导将不胜感激。