Currently I'm trying to implement app where on startup is SplashScreenFragment and after several seconds I switch to screen with BottomNavigationView
<?xml version="1.0" encoding="utf-8"?>
<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/app_navigation"
app:startDestination="@id/navigation_splash_screen">
<fragment
android:id="@+id/navigation_splash_screen"
android:name="com.example.test.SplashScreenFragment"
tools:layout="@layout/fragment_splash_screen">
<action
android:id="@+id/action_navigation_splash_to_feature1"
app:destination="@id/feature1_navigation"
app:popUpTo="@+id/navigation_splash_screen"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/navigation_test_1"
android:name="com.example.test.Fragment1" />
<fragment
android:id="@+id/navigation_test_2"
android:name="com.example.test.Fragment2" />
<fragment
android:id="@+id/navigation_test_3"
android:name="com.example.test.Fragment3" />
</navigation>
Then I define bottom_nav_menu.xml
as follows:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@id/navigation_test_1"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/bottom_nav_title_feature1" />
<item
android:id="@id/navigation_test_2"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/bottom_nav_title_feature2" />
<item
android:id="@id/navigation_test_3"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/bottom_nav_title_feature3" />
</menu>
Version of navigation components:
androidx.navigation:navigation-fragment-ktx:2.2.0
androidx.navigation:navigation-ui-ktx:2.2.0
Now after calling bottomNavigationView.setupWithNavController(findNavController(R.id.nav_host_fragment))
inside Activity
where nav_host_fragment
is defined inside activity layout all seems to work.
Issue is, when user pressing back button or navigate back and forward between two items of menu do not clean backstack, that means that after clicking to feature1 -> feature2 -> feature1 -> feature2, when user pressing back button navigation is as follows: feature1 -> feature2 -> feature1 -> outside of the app (cause of popUpToInclusive
on SplashScreenFragment
) while desired back navigation is: feature1 -> outside of the app.
Anyone successfully tried to use BottomNavigationView
where first item of bottom navigation is not startDestionation of navigation graph?
Edited as it seems that issue is startDestination not included graphs