我正在使用Navigation从Android Jetpack在屏幕之间进行导航。 现在,我想要动态地设置startDestination。
我有一个名为MainActivity的Activity, 以及两个Fragment,FragmentA和FragmentB。
var isAllSetUp : Boolean = // It is dynamic and I’m getting this from Preferences.
If(isAllSetUp)
{
// show FragmentA
}
else
{
//show FragmentB
}
我想使用导航架构组件来设置上述流程。目前我已经使用了以下的startDestination,但它不能满足我的要求。
<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/lrf_navigation"
app:startDestination="@id/fragmentA">
<fragment
android:id="@+id/fragmentA"
android:name="com.mindinventory.FragmentA"
android:label="fragment_a"
tools:layout="@layout/fragment_a" />
</navigation>
使用Android Navigation Architecture组件,是否可以有条件地设置startDestination?
NavigationUI.onNavDestinationSelected(menuItem, navController.getNavController());
。 - AskNilesh