No video

Safe Args with Navigation Component - Android Studio Tutorial

  Рет қаралды 50,979

Stevdza-San

Stevdza-San

Күн бұрын

🏆 My Online Courses
⭐Discount Coupon: LAUNCH-STEVDZA-SAN
stevdza-san.com
🐱‍👤 Wanna become a member? Join!
/ @stevdzasan
📸 Instagram
/ stevdza_san
The Navigation component has a Gradle plugin called Safe Args that generates simple object and builder classes for type-safe navigation and access to any associated arguments. Safe Args is strongly recommended for navigating and passing data, because it ensures type-safety.
Watch the previous video: • Navigation Component -...
** Add Dependency **
dependencies {
def nav_version = "2.3.0-alpha04"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
** Compile Options **
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
** Apply Plugin (Java) **
apply plugin: "androidx.navigation.safeargs"
** Apply Plugin (Kotlin) **
apply plugin: "androidx.navigation.safeargs.kotlin"

Пікірлер: 73
@guyyakobovich9873
@guyyakobovich9873 4 жыл бұрын
This is the best, short, straight to the point explanation I have seen on the subject. Thank you very much, you earned a new supporter
@MrDoge-yp8us
@MrDoge-yp8us 3 жыл бұрын
After half a day looking to solve my problem, you saved me. Thank you!
@christianmethot5941
@christianmethot5941 4 жыл бұрын
Thank you so much! You have no idea how your tutorials have helped us, making easy tasks that looked daunting and impossible. All the best.
@StevdzaSan
@StevdzaSan 4 жыл бұрын
Thank you Christian, I'm happy for that! 😊
@wearedoingsomething
@wearedoingsomething 3 жыл бұрын
Stefane brate zivio sto godina!!! Ovo mi treba!! Imas li ono nesto tipa buyMeCoffee ili patreon ? Zasluzio si pivo ili dva ili kafu, štagod ti više paše :D
@pawechilczuk7559
@pawechilczuk7559 3 жыл бұрын
Great explanation! I got stuck in one point, couldn't see ...FragmentArgs class - and saw in video, just need to rebuild project. Thanks a lot!
@unitubetv
@unitubetv Жыл бұрын
Very useful tutorial, thank you Stevdza-San
@lucye7320
@lucye7320 4 жыл бұрын
Really great tutorial, super concise. Thank you!
@ehtishamhassan8146
@ehtishamhassan8146 4 жыл бұрын
Very helpful tutorial. Thank You.
@aelafdev
@aelafdev 3 жыл бұрын
clear concise and to the point!!!
@xtanion
@xtanion 3 жыл бұрын
Thank You, Thanks for making these amazing videos
@noorullah5748
@noorullah5748 2 жыл бұрын
Thank you so much. It really helped
@tarsilacostalonga
@tarsilacostalonga 4 жыл бұрын
Hi, Stevdza. Great video, right to the point. Is there a video example showing how to pass more than 1 value with safe args? I would really appreciate this, because i'm struggling with this issue on my project. Thank you so much!!
@StevdzaSan
@StevdzaSan 4 жыл бұрын
You can pass multiple values using Array as a type, or your own data class as parcelable. I'll make a video about it in the future.
@tarsilacostalonga
@tarsilacostalonga 4 жыл бұрын
@@StevdzaSan Thank you, I apreciate that, I will be awaiting the video!! hahah
@pratikchauhan989
@pratikchauhan989 3 жыл бұрын
Amazing one Thankyou for this one
@chetanprajapati3085
@chetanprajapati3085 3 жыл бұрын
Great Tutorial
@ampo2004
@ampo2004 3 жыл бұрын
Do you sell courses or personalized tutoring? I really like the way you teach, simple, concsice and very good!
@noshingh521
@noshingh521 4 жыл бұрын
Thank you. that was Very helpful
@sudheeshmohan4357
@sudheeshmohan4357 Жыл бұрын
Good tutorial! 👍
@bro_chenzox
@bro_chenzox 4 жыл бұрын
What happened before the creation of the video, what resource gave an understanding of the topic especially for you, it is obvious that it was of high quality ?! Could you share? P.S. Subscribed
@StevdzaSan
@StevdzaSan 4 жыл бұрын
Android documentation and practice.
@bro_chenzox
@bro_chenzox 4 жыл бұрын
@@StevdzaSan Thanks, I have checked that, it's true. But at the moment 3:38 can we use `val args = SecondFragmentArgs.fromBundle(arguments!!)` or it is old decision?
@Mtorres1889
@Mtorres1889 3 жыл бұрын
my app dont generate de clasess, do you know why?
@deanuziel4545
@deanuziel4545 Жыл бұрын
Make sure you’ve implemented the safeArgs inside build.gradle
@quybuihai7041
@quybuihai7041 2 жыл бұрын
the Gradle version is new so I don't know how to add Safe Args. Can you help me?
@poonammishra6276
@poonammishra6276 Жыл бұрын
Nice Explanation, I have one question though how to pass an object by using safe arg?
@ronneyismael605
@ronneyismael605 3 жыл бұрын
You explain really great. Please make a video on MVVM Architecture.
@kerimmemmedzade8720
@kerimmemmedzade8720 3 жыл бұрын
He actually did...
@Android-sb8uo
@Android-sb8uo 4 жыл бұрын
I followed all of your guidelines even the documentation but I still get this error: Android linking resource failed, AAPT: error: failed writing to 'directory\project\app\build\intermediates untime_symbol_list\debug\R.txt': The data is invalid. (13). What does it mean? how to fix that?
@brandondelacruz934
@brandondelacruz934 4 жыл бұрын
Ive been having this problem where safeArgs arent working. Even tho its enabled in my gradle file
@StevdzaSan
@StevdzaSan 4 жыл бұрын
Rebuild your project, or close and run Android Studio again after you have synced your project.
@mauriciopriego1700
@mauriciopriego1700 3 жыл бұрын
thank you
@aliappdevelop
@aliappdevelop 3 жыл бұрын
Awesome tutorial but I have one question. What if I need to pass two parameters insted of one. Like Integer as well as String. Without passing object. It is possible??
@Alexwith
@Alexwith 3 жыл бұрын
Hey, man, thanks! You are cool! Im from Belarus and i dont know English, but im anderstand you and im anderstent how do what you tell!!!! Thanks, man!!!!
@rafidnagaradharmakusuma3487
@rafidnagaradharmakusuma3487 2 жыл бұрын
sir how to pass image from first fragment to second fragment , in your example you use int to pass the number
@platinumphonesandcomputers
@platinumphonesandcomputers Жыл бұрын
Am having challenges syncing the dependencies
@TheGoodOldDays-IsNow
@TheGoodOldDays-IsNow 2 ай бұрын
This worked 4 years ago, but it doesn't in 2024. I'm an experienced programmer, but totally new to Android. Can anyone point me in the right direction? the structure of the gradle.build files has completely changed in the meantime and something as simple as setting "classpath" gives an error.
@waleefalrooh8
@waleefalrooh8 2 жыл бұрын
The safearga doesnot genarate the classes🥲
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Rebuild your project
@waleefalrooh8
@waleefalrooh8 2 жыл бұрын
@@StevdzaSan i cleaned it and rebuild it so many times but still the same proplem
@StevdzaSan
@StevdzaSan 2 жыл бұрын
@@waleefalrooh8 Check your dependencies and plugin.
@waleefalrooh8
@waleefalrooh8 2 жыл бұрын
@@StevdzaSan i checked it now it is in the project but it's not in the java (generated) file.. i don't know where it is though
@StevdzaSan
@StevdzaSan 2 жыл бұрын
@@waleefalrooh8 Strange, you should ask on stackoverflow then..
@theai2020
@theai2020 Жыл бұрын
even after adding toString the app crashes there is something wrong with the code
@olamao
@olamao 3 жыл бұрын
Thanks a lot. I am having problems when trying to define val args : SecondFragmentArgs by navArgs(). The error says: "property delegate must have a getvalue". However I noticed that android didn´t generate the three classes (two for directions and one for arguments). Do you have any suggestion for me, please?
@Mtorres1889
@Mtorres1889 3 жыл бұрын
did you solved this?
@h.r.60
@h.r.60 4 жыл бұрын
So... should I be using fragments instead of activities now? How do they act with the application's main thread?
@StevdzaSan
@StevdzaSan 4 жыл бұрын
Navigation component is well structured and easy to use. Using fragments with just one activity is one of the main purposes of nav component. Btw more videos coming about nav component.
@arkamondal6160
@arkamondal6160 4 жыл бұрын
Sir, can you tell how to maintain the app menu using navigation component
@TriNguyen-ym3hf
@TriNguyen-ym3hf 3 жыл бұрын
i have a question, why do we use safe args if we have viewmodel-liveData ?. thanks
@codingmafia1642
@codingmafia1642 4 жыл бұрын
Great Video ,so how do I pass a value from Navigation MainActivity to any Fragments I switch to
@StevdzaSan
@StevdzaSan 4 жыл бұрын
Solution: your MainActivity should not contain anything except NavHostFragment. Use your fragments to handle everything else.
@codingmafia1642
@codingmafia1642 4 жыл бұрын
@@StevdzaSanThank u vm, but my real problem statement, I m selecting a user role from first Activity--->carry role value as an intent to MainActivity(comes with Navigation drawer side menu + fragments(home,gallery... etc) by default) and I m trying to pull the role from MainActivity to any Fragments that I switch to. I tried to the following in MainActivity where Navcontroller is setted. bundle.putString(...); NavController.setGraph(R.navigation.mobile_navigation,bundle); On receiving Fragments String role = getArguments.getString("role"); Only recieving the role onStartDestinationFragment which is Home but in others fragments(gallery,profile etc...) i m receiving null value. I tried safeArgs ,Bundles I still receiving null value of role when in other Fragments. 🙏Hope I m clear
@mohammadazrikhairuddin8753
@mohammadazrikhairuddin8753 3 жыл бұрын
I don't know why after I sync my project, the project that was supposed to be generated automatically is not there. Do you know the reason?
@nutankumari9977
@nutankumari9977 3 жыл бұрын
Build->clean project->rebuild project
@mohammadazrikhairuddin8753
@mohammadazrikhairuddin8753 3 жыл бұрын
@@nutankumari9977 Already done that before asking this yet still not showing
@vitquack4078
@vitquack4078 Жыл бұрын
Gradle dependency for SafeArgs is outdated
@mdjahidulislam9205
@mdjahidulislam9205 3 жыл бұрын
Dont understand the (by navargs) syntax , would you explain please
@StevdzaSan
@StevdzaSan 3 жыл бұрын
That's a property delegate. We are lazily getting arguments during variable declaration. Something similar to "by lazy {}". Classes with postfix "Args" and "Direction" are automatically generated by Safe Args plugin.
@mdjahidulislam9205
@mdjahidulislam9205 3 жыл бұрын
@@StevdzaSan thanks a lot.
@layly7961
@layly7961 3 жыл бұрын
Hello dears. I can't generate fragment direction in my project. Do you have any solutions? I have add class path and apply plugin but still not working.
@MiYakudzik
@MiYakudzik 2 жыл бұрын
I have the same problem. Did you find solution?
@layly7961
@layly7961 2 жыл бұрын
@@MiYakudzik it's already generated but just didn't show on that folder. You should declear your fragment direction as my example. Ex: val direction: FragmentDirection =
@layly7961
@layly7961 2 жыл бұрын
@@MiYakudzik and also if your project is java you should declear FragmentDirection f =
@layly7961
@layly7961 2 жыл бұрын
@@MiYakudzik it will show your generated direction after you declear this variable.
@MegaRockandroll09
@MegaRockandroll09 2 жыл бұрын
@@layly7961 Thank you so much. I almost gave up thinking the plugin is bugged
@Techydom
@Techydom 2 жыл бұрын
PLEASE SOMEONE SHOULD HELP HAVE RESEARCHED MY ASS OUT AND CANT FIND THE SOLUTION I RAN INTO THESE NAVCONTROLLER ERROR
@Techydom
@Techydom 2 жыл бұрын
THE APP JUST EXITS WITH THIS ERRORS
@amandasjoberg463
@amandasjoberg463 6 ай бұрын
how do I fix safeargs for java? My build.gradle file doesn't have a buildscript section, and my dependencies don't contain any classpaths I added the following to build.gradle(project): id("androidx.navigation.safeargs") version "2.5.3" apply false and id ("androidx.navigation.safeargs") in build.gradle(module). When I write the text of myArg is red. Something's wrong but I don't know what. Also in my java file (FirstFragment), how do I navigate to SecondFragment and send my data? Currently I navigate this way: NavHostFragment.findNavController(FirstFragment.this) .navigate(R.id.action_FirstFragment_to_SecondFragment); But I have a variable int count, and I want to send the value of it as myArg. How do I do that?
Type-Safe Navigation with the OFFICIAL Compose Navigation Library
10:03
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 32 МЛН
OMG what happened??😳 filaretiki family✨ #social
01:00
Filaretiki
Рет қаралды 12 МЛН
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 123 МЛН
Navigation Component - Android Studio Tutorial
12:11
Stevdza-San
Рет қаралды 173 М.
The ViewModel & LiveData Tutorial in Android Studio (Kotlin)
8:56
Navigation Component in Android Studio using Kotlin | Android Knowledge
21:19
How This New Battery is Changing the Game
12:07
Undecided with Matt Ferrell
Рет қаралды 150 М.
Type safe, multi-module best practices with Navigation Compose
6:03
Android Developers
Рет қаралды 46 М.
Scammed selling my MacBook, almost
15:09
Alex Ziskind
Рет қаралды 41 М.
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 32 МЛН