Day137 — navigation component
1 min readDec 23, 2019
This records things I learn about navigation component during a project.
Pass arguments
Fragment A -> Fragment B
and pass data
Be notice that although the above code having the arguments declared in the action tag of the source fragment (FragmentA), i.e. @id/fragment_a_to_b
. There is not a must to declare arguments passing from source to target fragment. You can simply declare the wanted arguments inside the target fragment tag. e.g.
<fragment
android:id="@+id/fragment_b"
android:name="com.jacky.testnavigationcomponent.FragmentB"
android:label="FragmentB"
tools:layout="@layout/fragment_b"> <argument
android:name="argString"
app:nullable="false" /></fragment>
SafeArgs can pick up the argument and generate proper class that you can use in target fragment, i.e. FragmentB.
private val argsParams by navArgs<FragmentBArgs>()
You can find the whole project in GitHub