navigation_main file
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/navigation_main_countries_fragment">
<fragment
android:id="@+id/navigation_main_countries_fragment"
android:name="com.test.app.fragments.CountriesFragment"
tools:layout="@layout/fragment_countries" />
<fragment
android:id="@+id/navigation_main_categories_fragment"
android:name="com.test.app.fragments.CategoriesFragment"
tools:layout="@layout/fragment_categories" />
</navigation>
Is it possible to remove app:startDestination="@id/navigation_main_countries_fragment" from navigation_main file and do it programmatically? If the int x was 0 then run countries_fragment otherwise categories_fragment.
I'm using Java language.
Please test your answer before posting it because many people posted their answers but unfortunately the answers do not work.