Is there a way to clear navArgs after using them? I have fragment A that opens fragment B with navArgs, then I navigate to fragment C and the user presses back, so fragment B is opened with the same navArgs and I don't want that.
Is there a way to navigate back to fragment B without the navArgs?
Thanks.
The answer suggested by Juanjo absolutely does work.
The only caveat is that you can't use the navArgs
property delegate to get at them since it's wrapped Lazy
.
Instead you just go through the underlying arguments
bundle.
For example, in FragmentB
// don't need to pull in the navArgs anymore
// val args: FragmentBArgs by navArgs()
override fun onResume() {
when (FragmentBArgs.fromBundle(arguments!!).myArg) {
"Something" -> doSomething()
}
// clear it after using it
arguments!!.clear()
}
// now they are cleared when I go back to this fragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With