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

КОМЕНТАРІ • 77

  • @hidaro9448
    @hidaro9448 Рік тому +8

    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 !

  • @youssef-attai
    @youssef-attai Рік тому +3

    That was very helpful, the whole series actually. Thank you so much.

  • @parthpatel8173
    @parthpatel8173 3 роки тому

    Thanks, Philipp. I was trying it for a couple of days and now I got a proper solution to fit this into MVVM

  • @mohameddarwish1347
    @mohameddarwish1347 4 роки тому +3

    Das macht Spaß, danke für diese großartige Arbeit

  • @ahmedabdeen4980
    @ahmedabdeen4980 2 роки тому

    Excellent video Phillip. Working with firebase functions was always painful. That is way better. Thanks!

  • @ziyadmansy6016
    @ziyadmansy6016 4 роки тому +11

    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 ❤️

    • @PhilippLackner
      @PhilippLackner  4 роки тому +5

      Thank you so much dude this makes me so happy❤️

    • @osmanmusse9432
      @osmanmusse9432 2 роки тому +1

      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

  • @mahmoudramadan8407
    @mahmoudramadan8407 3 роки тому

    you are doing amazing work, please keep it up

  • @jjhoninatan55sabadi
    @jjhoninatan55sabadi 4 роки тому +1

    I was waiting for this video!!! thank you

  • @salihuumar3138
    @salihuumar3138 Рік тому

    Thanks I have really learnt a lot in a short time

  • @sanooshbalakrishnan6051
    @sanooshbalakrishnan6051 3 роки тому

    Great video Buddy❤️

  • @chuka_obi5167
    @chuka_obi5167 3 роки тому +1

    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?

  • @quangtuan202
    @quangtuan202 Рік тому

    Thank you!

  • @talhac2796
    @talhac2796 Рік тому

    Thank you so much

  • @sheffomp
    @sheffomp 4 роки тому +1

    Great vid ! Waiting for App News's Tutorials !

  • @umerqaisar6015
    @umerqaisar6015 3 роки тому

    THE BEST

  • @muhamedmansour7427
    @muhamedmansour7427 3 роки тому

    i love you man ❤️❤️

  • @jakub3471
    @jakub3471 2 роки тому

    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.

  • @AlgeriaHere
    @AlgeriaHere 4 роки тому +3

    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 .

    • @PhilippLackner
      @PhilippLackner  4 роки тому +2

      Thanks, you can put your Firestore call in a try/catch block to catch firebase exceptions when something goes wrong

  • @redfox6089
    @redfox6089 3 роки тому +1

    Hello Philipp an Everyone!!!
    Should we use coroutineScope instead of globalScope, what do you think?

  • @gabrielfrancis7141
    @gabrielfrancis7141 4 роки тому

    bruh. i fully appreciate your work. though can you make a video on onboarding screens?

  • @mataal8770
    @mataal8770 10 місяців тому

    Hi bro how do you get the document reference using the await method?

  • @goamora8599
    @goamora8599 Рік тому

    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.

  • @brianquigley1940
    @brianquigley1940 2 місяці тому

    The tutorialDocument object works asynchronously? Does that mean the .get() can finish before the .set() ?

  • @mokamig
    @mokamig 2 роки тому

    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

  • @FckYouPlz
    @FckYouPlz 3 роки тому

    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?

    • @smonkey001
      @smonkey001 2 роки тому

      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.

  • @deepsheth1086
    @deepsheth1086 Рік тому +1

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

    • @jhNic
      @jhNic Рік тому

      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???

  • @sumitshukla6436
    @sumitshukla6436 4 роки тому +1

    Hello sir! What if there was an exception while adding or getting data? How coroutine will handle it?

  • @kekekeernest8920
    @kekekeernest8920 3 роки тому

    Please, help on how to create a fire data based

  •  3 роки тому

    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

    • @sigmatri
      @sigmatri 3 роки тому +1

      maybe you forget to import coroutines play services

  • @guy1407
    @guy1407 4 роки тому

    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 ?

  • @gigimushi6705
    @gigimushi6705 Рік тому

    hi, i dide't have the firestore to try this example, my question: how to make a firestore to make this example like you?

  • @mlktech1531
    @mlktech1531 4 роки тому +1

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

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      You can use savedInstanceState to save the current UI state of your app and load it when the user reopens it

    • @mlktech1531
      @mlktech1531 4 роки тому

      @@PhilippLackner do you have a vesio on how to use it?

  • @newsmasala701
    @newsmasala701 2 роки тому

    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.

  • @JsXCubED1
    @JsXCubED1 4 роки тому

    What if I'm using the snapshot listener for real-time updates?

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      That's not a task, so you just use it as usual

  • @GIULI4994
    @GIULI4994 Рік тому

    how do you check if the operation was successful though? try {} catch {} ???

  • @galizischebahn2648
    @galizischebahn2648 Рік тому

    Wouldn't it be better to place this logic in ViewModel and launch the coroutine in a viewModelScope?

  • @brianquigley1940
    @brianquigley1940 2 місяці тому

    Where is tvData bound to its view?

  • @mikejawoski5904
    @mikejawoski5904 4 роки тому

    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

    • @mikec4220
      @mikec4220 3 роки тому +1

      I think he wanted to focus on how Coroutines work in general and not on any particular app architecture... just kept it simple...

  • @atifabbasi7358
    @atifabbasi7358 3 роки тому

    how to handle exception while using await.?

  • @cherylm8210
    @cherylm8210 4 роки тому

    No errors and connecting to firebase (as I can see reads/Writes counts are not 0). But not actually reading and writing. Any ideas?

    • @cherylm8210
      @cherylm8210 4 роки тому

      Looks like its not executing the withContext block and data is also not being written to the database

    • @cherylm8210
      @cherylm8210 4 роки тому

      upon investigation it works on phone but not the emulator, but no idea why

  • @dombikpanda
    @dombikpanda 2 роки тому

    I wish you would have shown not taking all values, but taking them one by one. Who should do what all values

  • @karuneshpalekar5212
    @karuneshpalekar5212 4 роки тому +1

    Is it the same with realtime database?

    • @PhilippLackner
      @PhilippLackner  4 роки тому +2

      If those functions return a task object then that should be possible. That also works with firebase auth

    • @whoadityanawandar
      @whoadityanawandar 2 роки тому

      Did you try it with realtime db, looks like it doesn't work with realtime, .await() becomes an unresolved reference.

  • @dominicfischer2891
    @dominicfischer2891 4 роки тому +2

    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

  • @dawoodamir2011
    @dawoodamir2011 4 роки тому +1

    I have built a shoppong application using firestore in java seing this now making me want to convert the whole code to kotlin lol

    • @PhilippLackner
      @PhilippLackner  4 роки тому +2

      I know, I felt the same when I encountered that the first time 😂

    • @GakisStylianos
      @GakisStylianos 4 роки тому +2

      Yeap, time to join the cool kids

    • @dawoodamir2011
      @dawoodamir2011 4 роки тому

      I have already joined

  • @wavecycle
    @wavecycle 2 роки тому

    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

    • @mackomako
      @mackomako 2 роки тому +1

      No, it's not. It's only for demonstration.

  • @abdoghania2273
    @abdoghania2273 4 роки тому +1

    honestly my friend , do you think that native will die ?

  • @michaelchristensen8350
    @michaelchristensen8350 2 роки тому

    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.

    • @PhilippLackner
      @PhilippLackner  2 роки тому +1

      Compose doesn't change anything about how firebase works

    • @michaelchristensen8350
      @michaelchristensen8350 2 роки тому

      @@PhilippLackner Ok Its just not easy to implement when I am a newbie selflearner.