So, like the title says I'm trying to retrieve passed arguments from a bundle according to the documentation I'm following by using var args = GameWonFragmentArgs.fromBundle(arguments!!)
.
But Android Studio suggests using the following code:
var args = GameWonFragmentArgs.fromBundle(requireArguments())
I looked up the Android Documentation for Fragment and found that requireArguments()
returns a @NonNull Bundle or an IllegalStateException. Why does Android Studio suggest using it and what's the difference between the two?
Also, I couldn't find relevant documentation about fromBundle()
.
There is some api changes in androidx.fragment:fragment
requireArguments() --- method which returns a @NonNull Bundle or throws an IllegalStateException.
fromBundle(arguments!!) --- these case App may be crashed because of Null pointer exception. if arguments is null app will be crashed.
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