The safeargs component lets you eliminate bug-prone literal strings used as keys. It generates two classes for each fragment that has parameters: a Directions class to send data, and an Args class to receive it.
- [Instructor] When you pass values to a destination…they're passed as key value pairs in a bundle.…Each key must be spelled exactly the same…as it's defined in the fragment that receives it.…If you misspell it you'll get errors.…The traditional way of dealing with this…is to create constants for each key.…But Android offers a new tool called the Safeargs Component…that deals with this a little bit differently.…Safeargs generates classes that you can use…to send and receive values with methods that are created…for each parameter.…
To use safeargs start off in your project level gradle file…and add a new classpath.…It'll look like this.…I'll start with classpath then android.arch.navigation…:navigation-safe-args-gradle-plugin.…And then from there you can use the same navigation version…variable that you generated earlier.…
With $nav_version.…Double check the spelling of the classpath,…that's a little bit of typing and make sure…that you've spelled it correctly.…Next go to your gradle file for the module.…It's labeled app up here.…
Share this video
Embed this video
Video: Pass parameters using safeargs