Загрузка страницы

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
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
12 марта 2018 г. 5:30:01
00:16:23
Яндекс.Метрика