Coroutines will FREEZE your UI

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии •

  • @feanor2718
    @feanor2718 4 года назад +4

    Just reading about co routines and had a doubt about the freezing the main UI and I come to RUclips to see your other videos and u upload this xD

  • @DerCheckerzeigts
    @DerCheckerzeigts 4 года назад +1

    Sometimes I run into this issue because I launched to meany heavy tasks as coroutines inside the main thread. Had to refactor the code again to fix it..

  • @HienNguyen-xn7tr
    @HienNguyen-xn7tr 4 года назад +3

    will it help unfreeze it if i left it by my heater?

  • @VenewebTV
    @VenewebTV 3 года назад

    Excellent video, regards from Caracas, Venezuela

  • @sufyanshabbir1834
    @sufyanshabbir1834 4 года назад +2

    Thankyou mitch for this informative video..

  • @hnim2292
    @hnim2292 4 года назад +2

    Mitch, could you tell me what suspend function does? I googled it a lot but I still can't understand

    • @codingwithmitch
      @codingwithmitch  4 года назад +4

      It just means it must be executed in a coroutine. And it "suspends" the coroutine until complete

  • @GakisStylianos
    @GakisStylianos 4 года назад +24

    tl;dr: Coroutines are not magic. You still need to use your brain.

    • @codingwithmitch
      @codingwithmitch  4 года назад +4

      But some do not has gud brain

    • @GakisStylianos
      @GakisStylianos 4 года назад +1

      @@codingwithmitch Meanwhile, other people out there using coroutines to do some crazy shit with views. ( medium.com/androiddevelopers/suspending-over-views-19de9ebd7020 )

    • @codingwithmitch
      @codingwithmitch  4 года назад

      @@GakisStylianos Jesus that looks complicated

    • @GakisStylianos
      @GakisStylianos 4 года назад +5

      @@codingwithmitch I know right. Every time I browse what other people do on Medium I just feel more dumb instead of learning hahahaha

    • @anshumandhal
      @anshumandhal 4 года назад +1

      @@GakisStylianos I complete agree with you on that point. Sometime those medium articles are so complicated that it right away makes me want to stop learning altogether.

  • @peterkariuki9475
    @peterkariuki9475 4 года назад +2

    Can you help in doing budge count with textview especially in messaging.

  • @dominicfischer2891
    @dominicfischer2891 4 года назад +2

    Why do you do `CoroutineScope(Main).launch { ... }` instead of `GlobalScope.launch(Main) { ... }`? It's an extra allocation you don't need.

    • @codingwithmitch
      @codingwithmitch  4 года назад

      I'll make a video today about GlobalScope and why you shouldn't use it. Probably ever.

    • @dominicfischer2891
      @dominicfischer2891 4 года назад +2

      @@codingwithmitch The reason you shouldn't use GlobalScope is because of structured concurrency, to make sure all your asynchronous tasks are completed (or cancelled) before the application moves on.
      Creating a `CoroutineScope` without cancelling it or waiting for it, is equally as bad using `GlobalScope` (I sadly see this very often). In fact I could argue it is worse, since you may not know that it is not safe.
      I think it's important to address this in your video.

  • @pravinpatidar98
    @pravinpatidar98 3 года назад

    Thanks Mitch for the video

  • @jaydeepmalviay2582
    @jaydeepmalviay2582 6 месяцев назад

    What if the child job has been canceled but still its running due to heavy long running execution?

  • @srjlove2102
    @srjlove2102 4 года назад +2

    Please make a video on only network request using coroutine

    • @codingwithmitch
      @codingwithmitch  4 года назад +2

      Just create a retrofit request that returns a suspend function. Done

  • @weeraphongsombatboon9568
    @weeraphongsombatboon9568 4 года назад

    But what happens when i launch the Coroutine only 90000 times?

  • @rsrini7
    @rsrini7 4 года назад +2

    Thanks for the video .. Am i alone thought the title is Corona or Coroutine .... 😷

  • @jaloveast1k
    @jaloveast1k 4 года назад +5

    With 200k printlns I think it would've frozen even without launching additional coroutines

  • @shareemteofilo6257
    @shareemteofilo6257 3 года назад

    Awesome! Thank you

  • @ryugalaw
    @ryugalaw 4 года назад +1

    So two coroutines running on different dispatchers run in the same thread? Or does the dispatcher define what thread they run in?

    • @codingwithmitch
      @codingwithmitch  4 года назад +3

      The dispatcher defines what pool of threads the coroutine will start in. In the case of the MAIN dispatcher though, there is only one thread. The main thread.

  • @ahmedmourad1683
    @ahmedmourad1683 4 года назад +2

    I thought println doesn't work on Android 🧐

  • @soheibbettahar1996
    @soheibbettahar1996 4 года назад +2

    that was so helful thanks

  • @benchakalaka
    @benchakalaka 4 года назад

    Extremely useful. Thanks

  • @kde6769
    @kde6769 3 года назад

    keep it up!

  • @bro_chenzox
    @bro_chenzox 4 года назад

    After seeing main function, I got a little nervous thinking what the entry point is doing here. Tricky moment.

  • @it-6411
    @it-6411 4 года назад

    Coroutines are implementing their own "event loop", and when delay function called, it will resume coroutine through this time by event, so there's no magic here)

  • @Lovepreet-xs5qi
    @Lovepreet-xs5qi Год назад

    Thank you sir

  • @osamamohsen3993
    @osamamohsen3993 4 года назад

    #Best_channel
    Thanks never enough for you :)
    when I use GlobalScope it never freeze my app.
    what the difference between CoroutineScope & GlobalScope? what do you recommend for use?

  • @kgandkg
    @kgandkg 4 года назад +1

    Loved the example chosen and how clearly it demonstrates the concept. The aha moment was how a Coroutines Job is different from a Thread. Also see the very first video in this series ruclips.net/video/F63mhZk-1-Y/видео.html.
    But damn that font is freezing my 🧠 thread.

  • @anesabismail6111
    @anesabismail6111 4 года назад +1

    Wow, that's interesting, but what if we launched a coroutine using runblocking on the main dispatcher would that block the main thread?

  • @oscarperry641
    @oscarperry641 4 года назад

    wow i didnt know i can freeze the u i!!

  • @mianaliasjad
    @mianaliasjad 3 года назад

    Title should be "will delay() FREEZE your UI"

  • @TowardsClinicalPsychology
    @TowardsClinicalPsychology 4 года назад

    Hmmm the title of this video is almost like clickbait! You would never run a network request on the main thread. You would specify Dispatchers.IO in your child launch. It's an interesting "article" but your title and aim ruined it.

    • @codingwithmitch
      @codingwithmitch  4 года назад

      Yes I know. It's a demonstration to conceptualize how coroutines work

  • @pejmanazad5852
    @pejmanazad5852 4 года назад

    bye bye RXXXXXXXXXXXXX?

    • @codingwithmitch
      @codingwithmitch  4 года назад +1

      I would say so

    • @GakisStylianos
      @GakisStylianos 4 года назад

      @@codingwithmitch As someone newer to the Android world, I have directly been introduced to Coroutines so it's the only thing I know. And that awesome.
      However, what I fear is that when I start working in a company I will basically be fucked. I know they are using Java still, so RX most likely is there.
      I hope the knowledge translates backwards as well, as in I hope it's easier for me to jump into RX after understanding Coroutines a bit.

    • @guiorgy
      @guiorgy 4 года назад

      Also never touched RX!

    • @codingwithmitch
      @codingwithmitch  4 года назад

      @@GakisStylianos my guess is Rx will get phased out.

    • @GakisStylianos
      @GakisStylianos 4 года назад

      @@codingwithmitch This is a really awkward time then. Because for now, we will need to learn enough to work with the older projects, but it won't be that fun since in the near future it may not be that relevant anymore.

  • @bertjan1297
    @bertjan1297 4 года назад +2

    Basically you are explaining that coroutines won't run if you stress out your CPU. This also counts for threads and is so pointless to make a video about to be honest...