【发布时间】:2019-01-18 20:35:19
【问题描述】:
我有两个片段 A 和 B 我正在使用导航控制器从 A 导航到 B 当我回到 A 时导航控制器创建另一个 A 实例!不从堆栈中调用旧实例并增加 sack 大小,在这种情况下,堆栈大小将为 3 个片段, 我该如何解决这个问题?
这是我的graph.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/home_dest"
app:startDestination="@id/home_dest">
<fragment
android:id="@+id/a_dest"
android:name="com.intcore.e_commerce.e_commerce.ui.homefragment.HomeFragment"
android:label="@string/home"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/b_dest"
android:name="com.intcore.e_commerce.e_commerce.ui.favoritesfragment.FavoritesFragment"
android:label="@string/favorites"
tools:layout="@layout/fragment_favorites" /></avigation>
这是我用来导航的代码。
void onAClicked() {
Navigation.findNavController(this, R.id.nav_host_fragment).navigate(R.id.a_dest);
}
void onBClicked() {
Navigation.findNavController(this, R.id.nav_host_fragment).navigate(R.id.b_dest);
}
【问题讨论】:
-
我想
onAClicked在B片段上;那么为什么不从onAClicked调用Navigation.findNavController(requireActivity(), R.id.navHost).navigateUp()呢?
标签: android android-studio android-fragments android-intent