Created
November 28, 2021 17:05
-
-
Save prongbang/7d859d976df8beb8d887c5606b01a5f6 to your computer and use it in GitHub Desktop.
How to make a dynamic start destination in the Android Navigation Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.fragment.app.FragmentContainerView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/navigationHostFragmentMain" | |
android:name="androidx.navigation.fragment.NavHostFragment" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:defaultNavHost="true" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.main_activity) | |
initNavGraphStartDestination() | |
} | |
private fun initNavGraphStartDestination() { | |
setupNavGraphStartDestination( | |
fragmentContainerViewIdRes = R.id.navigationHostFragmentMain, | |
navigationGraphRes = R.navigation.main_nav_graph, | |
startDestinationIdRes = R.id.ndidFaceScanFragment, | |
arguments = arrayOf( | |
NavArguments( | |
key = "argsName", | |
value = "NDID-FACE-SCAN" | |
) | |
), | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment