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:

Watch more Android Performance Patterns here:

Join the G+ Community here :

#PERFMATTERS

Subscribe to the Android Developers channel at

Nguồn:https://u-os.org/

Xem Thêm Bài Viết Khác:https://u-os.org/cong-nghe

Author

34 Comments

  1. Reem Hazzaa Reply

    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. jason gomez Reply

    Loaders are deprecated as of Android P (API 28) https://developer.android.com/guide/components/loaders

  3. Shouldn't Loader be obsoleted now given that we have LiveData and ViewModel now?

  4. Yusuf Kabbara Reply

    Thanks for the good work, I think we have a broken link in the sample code link 🙁

  5. ansh sachdeva Reply

    +Doug Stevenson can you please provide the latest link to the source code? looks like the link is not working anymore

  6. why is no one mentioning external libaries … udacity brought me here & they didnt put a single word on it …. I mean you dont boil the ocean just to cross it… when there is a boat standing by to enjoy the ride… they could have at least mentioned it…

  7. HI where can I find the sample code it is not under the link you posted

  8. Anastasiya Ivanova Reply

    Thank you! Your link for the sample code does not work.

  9. Anjula Sashika Reply

    https://github.com/googlesamples/android-architecture/tree/todo-mvp-loaders/ ERROR 404

  10. Kaushik N. Sanji Reply

    What if I use AsyncTask in a Fragment, having interface callbacks to the Activity. Will this cause memory leaks too during configuration changes?

  11. Joseph Ralph Reply

    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?

  12. I really like the infos, but pleeeeease speak slower next time. I had to wind back ten times… 🙁

  13. Nishat Sayyed Reply

    first of all…you need to change your barber…..you know why

  14. Sebouh Aguehian Reply

    RxJava or an event bus is much simpler and cleaner.

  15. Kasper Finne Nielsen Reply

    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?

  16. There should've been a video on this long before asynctask imo.

  17. Dragon Master Reply

    Go and watch my youtube channel I need help and stuff

  18. Honestly, this video should just be a link to RxJava's github

  19. Arif Nadeem Reply

    You could write 200 lines of code to do something as trivial as threading using Loader's or you could write 4 lines of code which does something similar using RxJava!

  20. Jens Buysse Reply

    can you provide scenario's where async is best and loaders are best?

Write A Comment