Status Update
Comments
ap...@google.com <ap...@google.com> #2
Can you attach a sample project that reproduces your issue?
il...@google.com <il...@google.com> #3
I'm experiencing this issue in a commercial non-open source project so I'd have to provide extracted code fragments. The menu file for instance looks similar to this:
<menu>
<item
android:id="@+id/destination_one" />
<item
android:id="@+id/destination_two" />
<item
android:id="@+id/destination_three" />
<item
android:id="@+id/destination_four" />
</menu>
The menu item ids match the top level destination ids as for instance destination_one as required by the NavigationUI library.
The xml layout file of the main activity (there is only one activity) looks pretty much like this:
<androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.constraintlayout.widget.ConstraintLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/navigation_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/main_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/navigation_host_fragment"
app:menu="@menu/main_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
The main_navigation
is the first navigation graph I posted in the original post. The behavior I described above only affects the first bottomNavigation item which corresponds to the top level navGraph's startDestination.
b9...@gmail.com <b9...@gmail.com> #4
Yeah, what we're looking for is a full project (i.e., take a brand new project in Android Studio, put your few bits of code in, and make sure your problem reproduces) as there are a lot of little pieces that can make a difference here.
b9...@gmail.com <b9...@gmail.com> #5
Of course the logic of my project is more sophisticated but this reproduces the issue quite well. If you click the first BottomNavigation item N times you need N+1 system back navigation triggers to leave the app.
il...@google.com <il...@google.com> #6
So first, we plan to get rid of these APIs in the future. The only behavior for NavigationUI will be to always save and restore the state of the back stack. Luckily, NavigationUI is purposely built only on publicly available APIs so you could always copy our code and make your custom adjustments for whatever your desired behavior is.
The source of the bug is
We need to add a fix to ensure we take into account the proper destination on our side, but as I mentioned those APIs will go away in the future. So if you wanted to proactively create your own API, you could make your API navigate directly to the start destination instead of the graph. That would allow you to not wait on our release and ensure you always have your desired behavior going forward.
b9...@gmail.com <b9...@gmail.com> #7
Thanks a lot for your help! I basically removed the first embedded graph by moving the code directly into the topmost navGraph and as you said, navigate directly to the start destination. As far as I can tell, it seems to work now.
Description
For example: pathA/{id}?query1={query1} will fail.
This is a common use case and we should be sure to support it.