START BACKGROUND THREAD | UPDATE MAIN/UI FROM BACKGROUND THREAD | ANDROID STUDIO TUTORIAL
When we try to execute long-running operations on the app's main thread (also called the UI thread), we freeze the app's user interface. After a couple seconds, we get an "application not responding" dialog message with the option to force quit the app. To avoid this we have to move heavy operations like database manipulation and network requests onto a separate thread.
In this video, we will learn how to create such a separate worker thread in Android. For this, we can either create a class that extends Thread and override its run method or create a class that implements the Runnable interface and then pass this Runnable to a new Thread object.
These core Java classes build the foundation for classes like AsyncTask, HandlerThread, and ThreadPoolExecutor.
We will also learn how to send code from the background thread back to the UI thread by calling a post on a Handler that sends a runnable to the MessageQueue of the UI thread. To associate the Handler with the Looper of the main thread, we either instantiate it on the main thread or pass Looper.getMainLooper to the constructor.
Instead of creating a handler, we can also use the View classes post method or the Activity classes runOnUiThread method, which uses the main handler internally.
#AndroidStudio #AndroidDevelopment #code #programming
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «START BACKGROUND THREAD | UPDATE MAIN/UI FROM BACKGROUND THREAD | ANDROID STUDIO TUTORIAL», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.