AsyncTask + WeakReference - Android Studio Tutorial
In this video we will learn, how to use the AsyncTask class, which makes it easier to do operations on a background thread and publish the results on the UI/main thread, without having to manipulate threads and handlers ourselves.
For this we will subclass Asynctask, define 3 generic types for the params, the progress and the result and override 4 methods:
onPreExecute, where we do preparations on the UI thread, doInBackground where we do the heavy work on a background thread, onProgressUpdate where we publish the progress to the UI thread (for example to a ProgressBar), and onPostExecute where we get back the result from the background task.
In order to not leak memory by holding onto a strong reference to our MainActivity, we will make the AsyncTask static and keep a WeakReference to our Activity.
Example code:
https://gist.github.com/codinginflow/19ab87a9ea0a178dd77508ce9ce13bcf
____________________
⭐ Get my new MVVM Caching Course now:
https://codinginflow.com/caching
❗ Subscribe to the channel:
https://www.youtube.com/c/codinginflow?sub_confirmation=1
💲 Earn money by becoming an affiliate for my courses:
https://codinginflow.com/affiliate
📨 Subscribe to the Coding in Flow newsletter:
https://codinginflow.com/newsletter
💻 Hire me for your next project:
https://codinginflow.com/contact
💚 Donate to Coding in Flow with a message:
https://paypal.me/codinginflow
❓ Ask your programming questions in our chat:
https://discord.gg/TSnMvmc
📣 Follow Coding in Flow on other sites:
Facebook: https://www.facebook.com/codinginflow
Instagram: https://www.instagram.com/codinginflow
Twitter: https://twitter.com/codinginflow
Github: https://github.com/codinginflow
Видео AsyncTask + WeakReference - Android Studio Tutorial канала Coding in Flow
For this we will subclass Asynctask, define 3 generic types for the params, the progress and the result and override 4 methods:
onPreExecute, where we do preparations on the UI thread, doInBackground where we do the heavy work on a background thread, onProgressUpdate where we publish the progress to the UI thread (for example to a ProgressBar), and onPostExecute where we get back the result from the background task.
In order to not leak memory by holding onto a strong reference to our MainActivity, we will make the AsyncTask static and keep a WeakReference to our Activity.
Example code:
https://gist.github.com/codinginflow/19ab87a9ea0a178dd77508ce9ce13bcf
____________________
⭐ Get my new MVVM Caching Course now:
https://codinginflow.com/caching
❗ Subscribe to the channel:
https://www.youtube.com/c/codinginflow?sub_confirmation=1
💲 Earn money by becoming an affiliate for my courses:
https://codinginflow.com/affiliate
📨 Subscribe to the Coding in Flow newsletter:
https://codinginflow.com/newsletter
💻 Hire me for your next project:
https://codinginflow.com/contact
💚 Donate to Coding in Flow with a message:
https://paypal.me/codinginflow
❓ Ask your programming questions in our chat:
https://discord.gg/TSnMvmc
📣 Follow Coding in Flow on other sites:
Facebook: https://www.facebook.com/codinginflow
Instagram: https://www.instagram.com/codinginflow
Twitter: https://twitter.com/codinginflow
Github: https://github.com/codinginflow
Видео AsyncTask + WeakReference - Android Studio Tutorial канала Coding in Flow
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Looper, MessageQueue & Handler Explained - Android Studio Tutorial](https://i.ytimg.com/vi/TN-CGfzvBhc/default.jpg)
![Memory Leaks on Android](https://i.ytimg.com/vi/bNM_3YkK2Ws/default.jpg)
![How to Start a Background Thread in Android](https://i.ytimg.com/vi/QfQE1ayCzf8/default.jpg)
![Asynctask in Android -Theory | Android Tutorial for Beginner](https://i.ytimg.com/vi/zHGgSd1wvxY/default.jpg)
![AsyncTask and AsyncTaskLoader (Android Development Fundamentals, Unit 3: Lesson 7.1)](https://i.ytimg.com/vi/V60KoFaAQVE/default.jpg)
![AsyncTasks | What When How in Android](https://i.ytimg.com/vi/iJa5Uhvgbio/default.jpg)
![](https://i.ytimg.com/vi/dbu7PF_hzwI/default.jpg)
![BottomNavigationView with Fragments - Android Studio Tutorial](https://i.ytimg.com/vi/tPV8xA7m-iw/default.jpg)
![Kotlin Crash Course for Java Developers](https://i.ytimg.com/vi/pXdY1B-KVJg/default.jpg)
![Model View View-Model (MVVM): Getting Started](https://i.ytimg.com/vi/ijXjCtCXcN4/default.jpg)
![JobScheduler - Android Studio Tutorial](https://i.ytimg.com/vi/3EQWmME-hNA/default.jpg)
![Bound Services on Android](https://i.ytimg.com/vi/_xNkVNaC9AI/default.jpg)
![AsyncTask in Android Practicle | Android Tutorial for beginners](https://i.ytimg.com/vi/EThkglxLxSM/default.jpg)
![Fragment to Fragment/Activity Communication - Android Studio Tutorial](https://i.ytimg.com/vi/i22INe14JUc/default.jpg)
![SQLite Database Tutorial for Android Studio](https://i.ytimg.com/vi/hDSVInZ2JCs/default.jpg)
![Download an Image in Android Studio Using AsyncTask](https://i.ytimg.com/vi/6FMqgAzKuOg/default.jpg)
![Android REST API app volley tutorial](https://i.ytimg.com/vi/8UgFclFBPcM/default.jpg)
![Android Services Tutorial | Background Tasks and Services | Android Development Training | Edureka](https://i.ytimg.com/vi/MV2mB1Wev2c/default.jpg)
![Running Android tasks in background threads | 34 | Android Development Tutorial for Beginners](https://i.ytimg.com/vi/IVFWC0rwfL4/default.jpg)
![BroadcastReceiver Tutorial Part 1 - STATIC RECEIVERS - Android Studio Tutorial](https://i.ytimg.com/vi/8FJ3oOpHszc/default.jpg)