GlobalScope vs. CoroutineScope - THIS Is the Difference

Поділитися
Вставка
  • Опубліковано 5 тра 2023
  • Follow for more Android & Kotlin tips 🙌

КОМЕНТАРІ • 29

  • @rgfnevess
    @rgfnevess 11 місяців тому +6

    I am loving your reels like this one. Thanks!

  • @SiamakAshrafi
    @SiamakAshrafi Рік тому +3

    OK ... Thanks. And If you ask ChatGPT you get a very good explanation with code examples showing the difference in Compose code which makes it very clear!

  • @dineshrandy9246
    @dineshrandy9246 6 місяців тому

    Wow, thanks a lot! Your information take me to the next level.

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

    Love it! Thanks

  • @malandev
    @malandev 5 місяців тому

    Thank you ❤

  • @youtubebillwebhome
    @youtubebillwebhome 4 місяці тому

    Thank u Philipp ❤

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

    I would like to work with you as an intern :D

  • @ahmadprogrammer136
    @ahmadprogrammer136 7 місяців тому

    Please coulde you add a translation for your videos for arabic please

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

    If however I want to run a computation when the onStop of a fragment is called, what do I use?

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

      Depends on the computation and if it's bound to the screen or not

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

    But what if i added a job inside globalScope context and cancle it anytime isn't work?

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

      Works, but that's independent of what a coroutine scope is used for

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

    well, I need to download something independent on any activity and it should continue to download even if you switch activities. So in this case what should I use?

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

    What if I'm writing something to local DB and want to be sure that the data will be written if the user decides to exit application? Should I use GlobalScope or CoroutineScope with dispather IO?

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

      WorkManager might be your solution

    • @firstnamelastname-oy7es
      @firstnamelastname-oy7es Рік тому

      Could you put a global boolean called "writing data" and then when you launch a data writing co-routine, set it to true, and when your co-routine is done writing data, have it set the boolean to false and cancel it?
      Then over ride on pause/on destroy so they enter a busy while-loop checking for writing data == false, and when it does equal false, finish up destruction and call super destroy.
      That way when the user closes the app, the app will hang until data has been finished writing.

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

    what if globalscope is used inside viewmodel?

    • @mouzinu
      @mouzinu Рік тому +2

      It is still a global scope

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

    And viemodelscope?

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

      It lives as long as the viewmodel does

  • @Danc243
    @Danc243 Рік тому +2

    Does Coroutine Scope cancels itself when the code block is finished ?

    • @PhilippLackner
      @PhilippLackner  Рік тому +3

      The job is finished, but a scope needs to be canceled by you

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

      @@PhilippLackner Same question but for GlobalScope, does it get canceled when the code is finished?

  • @airflow.777
    @airflow.777 Рік тому

    Can't we cancel global scope from inside when job is done?

    • @PhilippLackner
      @PhilippLackner  Рік тому +2

      You can cancel the job but not the scope

    • @airflow.777
      @airflow.777 Рік тому

      @@PhilippLackner understood, thank you Philip

  • @mohamedsanoob.k1116
    @mohamedsanoob.k1116 Рік тому +2

    What about MainScope() sir?