I have a String
type arg send from NewCodeFragment
to MainFragment
.
If I set a default value, then I got a 'too many args' error.
How can I set a default value? My understanding is if I send a arg, then the destination fragment will receive the arg, else it will receive the default value. Wrong?
Problem code:
navigation
XML:
<argument
android:name="aArg"
app:argType="string"
app:nullable="true"
android:defaultValue="@null" />
fragment.class
:
val aArg="abc"
// build error, it says too many args
this.findNavController().navigate(NewCodeFragmentDirections.actionNewCodeFragmentToMainFragment(aArg))
No problem code:
navigation
XML:
<argument
android:name="aArg"
app:argType="string"
app:nullable="true"/> // remove android:defaultValue="@null"
fragment.class
:
val aArg="abc"
this.findNavController().navigate(NewCodeFragmentDirections.actionNewCodeFragmentToMainFragment(aArg))
Another no problem code:
navigation
XML:
<argument
android:name="aArg"
app:argType="string"
app:nullable="true"
android:defaultValue="@null" />
fragment.class
:
val aArg="abc"
this.findNavController().navigate(NewCodeFragmentDirections.actionNewCodeFragmentToMainFragment()) // remove aArg