Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8)

Published on Apr 12, 2016 54,689 views

Let’s say you’ve got some 20 bitmaps being decoded on a worker thread. Well, what happens if your activity is destroyed before that work completes?

In this video Doug Stevenson explains Loaders. A super-helpful class that can give you insight into how the activity lifecycle is changing, so that you can better understand how to address threaded work that might be in flight.

See Android Architecture sample code here: https://goo.gl/MWXVav

Watch more Android Performance Patterns here: http://goo.gl/4ZJkY1

Join the G+ Community here : http://goo.gl/g7mxmI


Subscribe to the Android Developers channel at http://goo.gl/GEh1ds

  • i81u812
    i81u812 2 года назад I can't stop looking at your chin
  • Doug Stevenson
    Doug Stevenson 2 года назад +i81u812 lol! I have a blend of light and dark facial hair (due to alopecia, and it changes slightly over time) and I was surprised to see that the video camera totally exaggerates the contrast. It is kind of distracting here, sorry about that!
  • YoupSolo
    YoupSolo 8 месяцев назад you can apply this style to fix it <style name="chin"> <item name="android:layout_width">wrap_content</item> <item name="android:gravity">center_horizontal</item> </style>
  • amicloud
    amicloud 2 года назад Honestly, this video should just be a link to RxJava's github
  • Yusuf Kabbara
    Yusuf Kabbara 10 месяцев назад Thanks for the good work, I think we have a broken link in the sample code link :(
  • maslada
    maslada 2 года назад There should've been a video on this long before asynctask imo.
  • Kasper Finne Nielsen
    Kasper Finne Nielsen 2 года назад I think many of the solutions including rxJava or loaders tends to be very complicated. Especially when you want to be able to handle orientation changes. I think the far simplest way is to use IntentService with LocalBroadcastManager. What do you think about that? What are the advantages of using loaders instead of IntentService with LocalBroadcastManager?
  • Juil
    Juil 2 года назад Any updates to you questions?
  • azzum waqar
    azzum waqar 11 месяцев назад why do developers have to do so much work lol :(
  • Brian Chu
    Brian Chu 9 месяцев назад Shouldn't Loader be obsoleted now given that we have LiveData and ViewModel now?
  • Sajjad Khan
    Sajjad Khan 1 месяц назад sample code link is broken
  • Romina V.
    Romina V. 5 месяцев назад The links in the video are broken.
  • Kaushik N. Sanji
    Kaushik N. Sanji Год назад What if I use AsyncTask in a Fragment, having interface callbacks to the Activity. Will this cause memory leaks too during configuration changes?
  • Jens Buysse
    Jens Buysse 2 года назад can you provide scenario's where async is best and loaders are best?
  • Doug Stevenson
    Doug Stevenson 2 года назад +Jens Buysse To put it briefly, I would not use AsyncTask for anything that could block indefinitely (network), could run for a long time, or should not be repeated. Loaders are better for those things, IMO. AsyncTask is better for short bursts of CPU-oriented work that would cause jank or delays on the main thread, like parsing some JSON, maybe a quick db lookup, or decoding a bitmap. Of course, there are a lot of ways to get things done, and it's a matter of opinion what's best in some cases.
  • Jens Buysse
    Jens Buysse 2 года назад Thanks for the comment!
  • TheCsabi86
    TheCsabi86 2 года назад Why isn't the CC available? :-(
  • Sebouh Aguehian
    Sebouh Aguehian 2 года назад RxJava or an event bus is much simpler and cleaner.
  • Reem Hazzaa
    Reem Hazzaa 2 месяца назад I would like to thank all developers in the comment section because i get to know so much info just by reading your comments. You guide me into my learning journey so thank you :)
  • Абакумов Андрей
    Абакумов Андрей 2 года назад Don't ever use Loaders! I said enough
  • Nick Ra
    Nick Ra 2 года назад +Абакумов Андрей Please elaborate.
  • Anastasiya Ivanova
    Anastasiya Ivanova Год назад Thank you! Your link for the sample code does not work.
  • Pedro Varela
    Pedro Varela 8 месяцев назад old framework stuff, move to live data people
  • doom77777
    doom77777 2 месяца назад What?
  • mr vrctt
    mr vrctt Год назад Code link is not working.
  • Joseph Ralph
    Joseph Ralph Год назад How does LoaderManager handle the orientation change? Does it call onStopLoading() and onStartLoading() ? As per my sample program, no Loader life cycle method was called. Does LoaderMnagaer caches the data delivered by the Loader and it calls the onLoadFinished() with the cached data?
  • Stephen Rose
    Stephen Rose 2 года назад is this new? how did I never hear about this?
  • Viktor Yakunin
    Viktor Yakunin 2 года назад +Stephen Rose It's there since android 3 - Honeycomb
  • Akhil Gada
    Akhil Gada 9 месяцев назад I think probably the documention for loaders came latter.