Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When retrieving passed arguments from a bundle, why does Android Studio warn and suggest using requireArguments() instead of arguments!!?

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().

like image 605
Varad G Avatar asked Mar 02 '23 02:03

Varad G


1 Answers

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.

like image 171
sasikumar Avatar answered Apr 07 '23 05:04

sasikumar