![](/img/trans.png)
[英]How to navigate to Half Fragment ? (Navigation Architecture Component)
[英]Navigation Architecture Component: How i can navigate a fragment from the back stack?
我有兩個片段A和B我回到A時使用導航控制器從A導航到B,導航控制器創建A的另一個實例! 不從堆棧中調用舊實例並增加麻袋大小,在這種情況下,堆棧大小將為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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.