Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Why You Need To Use Coroutines in Android and How | MVVM Example

  • tutorialsEU - Android
  • 2021-10-12
  • 1350
Why You Need To Use Coroutines in Android and How | MVVM Example
Coroutines in AndroidMVVMmvvm androidandroid mvvm tutorialandroid tutorialstutorials to use coroutinesUse Coroutines in Androidcoroutines tutorialstutorials in androiddenis panjutadenis panjuta kotlindenis panjuta androiddenis panjuta udemyudemy tutorialandroid tutorial for beginners kotlinkotlin tutorial
  • ok logo

Скачать Why You Need To Use Coroutines in Android and How | MVVM Example бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Why You Need To Use Coroutines in Android and How | MVVM Example или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Why You Need To Use Coroutines in Android and How | MVVM Example бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Why You Need To Use Coroutines in Android and How | MVVM Example

In this video Learn how to use Coroutine with Retrofit and MVVM

Become an amazing Android Developer: https://bit.ly/3l6vG86

Free Android Download here: https://page.tutorials.eu/android

What is Coroutine


In Android executing a long-running operation like network calls, database operations or large computations blocks the *Main thread* which happens to be the *UI thread* responsible for rendering the UI widgets that the user can see. To avoid blocking the main thread we need to run these long-running operations on a separate thread outside of the main thread which is known as background thread. This is where Coroutine and multi-threading come in. Coroutine basically simplifies asynchronous programming on android and allows operations to run without blocking the main thread.


Lets look at some examples from the previous parts of the series:




This is a method to fetch *rick and morti characters* from an ApiService, this process is going to block the UI thread because it is been performed over a network call and we don't want this to happen that is why we used the built in Callback in the Retrofit library to execute it on the background thread.




But we can make this function shorter and more readable with the use of Coroutine


Modify the project to use Coroutine


Now let's modify this project to use Coroutine. This is the third part of two previous lessons, if you are new to Retrofit and MVVM then you need to check out the part one and two.


To use coroutines and the built-in scopes we add the following dependencies


Now let us modifier the method definition in the ApiService to use coroutine


To make fetchCharacters use coroutine, first, we added the suspend modifier at the beginning of the function then we remove the Call interface from the return type.


Back to the repository, we will have an error


This is because the suspend function can either be called in another suspend function or a coroutine scope so we need to also add a suspend function to this method.


Coroutine Scope


To finally execute this function we need a coroutine scope. Coroutines follow a principle of structured concurrency which means that new coroutines can only be launched in a specific CoroutineScope. If you create a scope and don't clear it at the end of the operation it can cause a memory leak and you wouldn't want that. In android, there is a built-in scope that can be used for specific classes.


viewModelScope - This is scoped to the ViewModel class so that a coroutine automatically gets canceled when the ViewModel class is cleared.
lifecycle scope- This is scoped to Activities and Fragments so a coroutine launched by it gets canceled when they are destroyed.


You can also create your own scope, create a job and attach it to the scope so that you can call cancel on the job once the execution is completed.




tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
Stay tuned and subscribe to tutorialsEU: https://goo.gl/rBFh3x

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]