Coroutines with Firebase Firestore - Kotlin Coroutines
Вставка
- Опубліковано 13 кві 2020
- In this video you will learn how you can use Firebase in combination with coroutines to avoid callback hell.
⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses...
💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
elopage.com/s/philipplackner/...
Firebase Coroutine dependency:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'
Regular Android tutorials on my Instagram: / philipplackner_official
Checkout my GitHub: github.com/philipplackner
I've been smashing my head around this issue for two days, and you just explained how to fix it in 9 minutes. Thank you so much !
That was very helpful, the whole series actually. Thank you so much.
Thanks, Philipp. I was trying it for a couple of days and now I got a proper solution to fit this into MVVM
Das macht Spaß, danke für diese großartige Arbeit
Excellent video Phillip. Working with firebase functions was always painful. That is way better. Thanks!
This is the one and only bookmarked UA-cam Channel as i visit it everyday to see your new Content, You taught me what my University didn't, Thanks a lot for instructing me from Scratch in a very interesting way ❤️
Thank you so much dude this makes me so happy❤️
me too man I really appreciate what philipp is bringing to the android community, probably one of the best teachers, PS I'm from London
you are doing amazing work, please keep it up
I was waiting for this video!!! thank you
You're welcome 👍
Thanks I have really learnt a lot in a short time
Great video Buddy❤️
This is a great tutorial. I learn so much watching your videos! hank you Phillip! One question, will this approach also work with Firebase real time database?
Thank you!
Thank you so much
Great vid ! Waiting for App News's Tutorials !
Thanks! It will start on 18. April!
THE BEST
i love you man ❤️❤️
No homo.
Great, except that I have to use runBlocking{} to select the image from the db and store it in a variable, because for me all the code is passed in and then the database code is executed at the end.
very nice tutorial thank you , there is little question about this tutorial , now we use coroutines to get rid of callbacks , but how about getting the result of input , we usally have a task and we check if it was sucessful or not , how is it possible to do that with coroutine thank you .
Thanks, you can put your Firestore call in a try/catch block to catch firebase exceptions when something goes wrong
Hello Philipp an Everyone!!!
Should we use coroutineScope instead of globalScope, what do you think?
bruh. i fully appreciate your work. though can you make a video on onboarding screens?
Hi bro how do you get the document reference using the await method?
Can you do a video like this for Firebase/Firestore, but for Jetpack Compose instead of xml? Struggling to figure out how to get the Firestore data back into the app.
The tutorialDocument object works asynchronously? Does that mean the .get() can finish before the .set() ?
Good morning, could you help me how I could get a collection of data and save it in an arraylist to be able to use it within the application, thank you very much
Someone has already asked this in this comment section but I want a specific answer about error handling - when I was using Firestore DB I always used "addOnSuccessListener()" and "addOnFailureListener()" for error handling. You said that I can wrap the entire call with try/catch but what if I have multiple calls inside that try/catch block? how will I know to which call was the error thrown?
Good question. If you absolutely have to handle each call's error differently then you have to do try/catch block separately. In reality, things like "404 user not found" and "404 user payment not found" are different error and you can differentiate them in one try/catch error block. Most of the time, people just throw a general error message. It's an ugly problem you will have to write the same extra shit even with RxJava.
hey @Philipp Lackner ....i have a problem here i am getting error of "Unresolved reference of await" ....can you tell me why i can not call await ...
me too, the await can't be call for some reason
Suspend function 'await' should be called only from a coroutine or another suspend function
I never heard of firebase before watching this video, I am really fresh to firebase, maybe I messed up when I am setting up those gradle???
Hello sir! What if there was an exception while adding or getting data? How coroutine will handle it?
You can wrap it into try/catch
Please, help on how to create a fire data based
Hi thanks for your video but the interesting thing is the ".await" is not showing in the document reference why is that?? i already imported firebase-ktx
maybe you forget to import coroutines play services
ERROR =
Cannot fit requested classes in a single dex file (# methods: 87057 > 65536)
Please kindly help
Also - should we prepare/login/create account for firebase ?
hi, i dide't have the firestore to try this example, my question: how to make a firestore to make this example like you?
Great vedio thanks .
In my app am reading a lot of photos with view pager ,so like i swipe till page 50 and close the app , I want she i reopen the i return to last page i was in (page50) and continue...
You can use savedInstanceState to save the current UI state of your app and load it when the user reopens it
@@PhilippLackner do you have a vesio on how to use it?
Trying to fix this from last 2 days, error says FATAL EXCEPTION and in my device it displays message: "Application stopped working". Please help me to resolve this.
What if I'm using the snapshot listener for real-time updates?
That's not a task, so you just use it as usual
how do you check if the operation was successful though? try {} catch {} ???
Yes
Wouldn't it be better to place this logic in ViewModel and launch the coroutine in a viewModelScope?
Where is tvData bound to its view?
I know this video is about coroutines and Firestore, but should've mentioned that this app architecture of having the model and calling the Firebase service from the UI layer is not scalable and creates tightly coupled code, which is not recommended
I think he wanted to focus on how Coroutines work in general and not on any particular app architecture... just kept it simple...
how to handle exception while using await.?
try/catch
No errors and connecting to firebase (as I can see reads/Writes counts are not 0). But not actually reading and writing. Any ideas?
Looks like its not executing the withContext block and data is also not being written to the database
upon investigation it works on phone but not the emulator, but no idea why
I wish you would have shown not taking all values, but taking them one by one. Who should do what all values
Is it the same with realtime database?
If those functions return a task object then that should be possible. That also works with firebase auth
Did you try it with realtime db, looks like it doesn't work with realtime, .await() becomes an unresolved reference.
Btw, You didn't need to use the `Dispatchers.IO` here. The (IO) operation being performed here is already being done asynchronously, coroutines just makes it easier to chain. Cheers
I have built a shoppong application using firestore in java seing this now making me want to convert the whole code to kotlin lol
I know, I felt the same when I encountered that the first time 😂
Yeap, time to join the cool kids
I have already joined
Is it good practice with Firestore to retrieve the record after you set() it? Or were you just doing that to demonstrate the successful set()? Thanks for the great work
No, it's not. It's only for demonstration.
honestly my friend , do you think that native will die ?
No it's still the preferred way to make android apps
still ???
@@PremKumar-zy6ls yes
Could you make this small example just instead showing how to get, and set document fields in firestore, but do it with jetpack compose. These videos are great, but they are very dated now.
Compose doesn't change anything about how firebase works
@@PhilippLackner Ok Its just not easy to implement when I am a newbie selflearner.