NavigationUI 使用片段参数导航
NavigationUI navigate with fragment parameter
我有 3 个相同的片段(片段 A)和 1 个显示错误数据的片段(片段 B)。
我如何在不创建 3 个保存操作的情况下导航到 fragmentB 和从 fragmentB 导航?
为了以防万一,我将附上我设法实现的代码:
<fragment
android:id="@+id/nav_notifications"
...
tools:layout="@layout/fragment_webview">
<action
android:id="@+id/to_nav_error"
app:destination="@id/nav_error" />
</fragment>
<fragment
android:id="@+id/nav_profile"
...
tools:layout="@layout/fragment_webview">
<action
android:id="@+id/to_nav_error"
app:destination="@id/nav_error" />
</fragment>
<fragment
android:id="@+id/nav_error"
android:name="ru.investel.client.screen.main.fragments.ErrorFragment"
tools:layout="@layout/fragment_error">
</fragment>
为了导航,我使用了:
navController.navigate(R.id.to_nav_error, bundle);
// to return:
navController.popBackStack();
我有 3 个相同的片段(片段 A)和 1 个显示错误数据的片段(片段 B)。 我如何在不创建 3 个保存操作的情况下导航到 fragmentB 和从 fragmentB 导航?
为了以防万一,我将附上我设法实现的代码:
<fragment
android:id="@+id/nav_notifications"
...
tools:layout="@layout/fragment_webview">
<action
android:id="@+id/to_nav_error"
app:destination="@id/nav_error" />
</fragment>
<fragment
android:id="@+id/nav_profile"
...
tools:layout="@layout/fragment_webview">
<action
android:id="@+id/to_nav_error"
app:destination="@id/nav_error" />
</fragment>
<fragment
android:id="@+id/nav_error"
android:name="ru.investel.client.screen.main.fragments.ErrorFragment"
tools:layout="@layout/fragment_error">
</fragment>
为了导航,我使用了:
navController.navigate(R.id.to_nav_error, bundle);
// to return:
navController.popBackStack();