Kotlin Coroutine için örnek proje

Overview

Kotlin Coroutines

Screenshot

Kotlin Coroutines: Senkron kod yazarak asenkron uygulamalar geliştirmeye yarayan bir eklentidir.

Network istekleri cevap gelene kadar bulunduğu thread'i bekletme moduna alır ve sonraki işlemleri bloklar.

Main thread (ana işparçası) içerisinde yapılan network istekleri, Main thread'i blokladığı için uygulama; UI işlemlerini gerçekleştirecek fonksiyonları çağıramaz.

Eğer network istek işlemi uzun sürer ve bir şekilde başarısız olursa bu durum uygulama yanıt vermiyor (Application Not Responding - ANR) hatalarına sebep olacaktır.

Bu sorunu ortadan kaldırmak ve daha iyi bir kullanıcı deneyimi sağlamak için network istekleri gibi işlemleri Main thread yerine background'ta yani arkaplanda yapmamız gerekir.

Ve tabii ki arkaplanda yapılan bu operasyonların sonuçlarını Main thread'e bildirmemiz gerekecektir.

Bu örneğimizde bu işlemler için ViewModel ve LiveData yapılarını kullanacağız.

Detaylı açıklamaları MainActivityViewModel ve MainActivity içerisinde bulabilirsiniz.


Kullandığımız API: https://api2.binance.com/api/v3/ticker/24hr

Kotlin Coroutine kullanmadan yapılan istekler için istatistikler şu şekilde;



2021-11-24 00:03:16.098/applog: sendGetWithHttpURLConnection -> started

2021-11-24 00:03:18.417/applog: sendGetWithHttpURLConnection -> finished

2.4 sn boyunca Main Thread bloklanıyor.


2021-11-24 00:03:18.469/applog: sendGetWithOkHttp -> started

2021-11-24 00:03:20.654/applog: sendGetWithOkHttp -> finished

2.2 sn boyunca Main Thread bloklanıyor.

You might also like...
This Project for how to use  MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.
This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.

Clean-architecture This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture. Why i should us

Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs

Zipline This library streamlines using Kotlin/JS libraries from Kotlin/JVM and Kotlin/Native programs. It makes it possible to do continuous deploymen

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

Android + Kotlin + Github Actions + ktlint + Detekt + Gradle Kotlin DSL + buildSrc = ❤️

kotlin-android-template 🤖 A simple Github template that lets you create an Android/Kotlin project and be up and running in a few seconds. This templa

LifecycleMvp 1.2 0.0 Kotlin  is MVP architecture implementation with Android Architecture Components and Kotlin language features
LifecycleMvp 1.2 0.0 Kotlin is MVP architecture implementation with Android Architecture Components and Kotlin language features

MinSDK 14+ Download Gradle Add to project level build.gradle allprojects { repositories { ... maven { url 'https://jitpack.io' }

Opinionated Redux-like implementation backed by Kotlin Coroutines and Kotlin Multiplatform Mobile

CoRed CoRed is Redux-like implementation that maintains the benefits of Redux's core idea without the boilerplate. No more action types, action creato

👋 A common toolkit (utils) ⚒️ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! 🍭

Toolkit [ 🚧 Work in progress ⛏ 👷 🔧️ 🚧 ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile.
An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile.

An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile. 项目架构主要分为原生系统层、Android/iOS业务SDK层、KMM SDK层、KMM业务逻辑SDK层、iOS sdkfra

Owner
Murat YÜKSEKTEPE
Software Engineer
Murat YÜKSEKTEPE
Kotlin coroutine capable Finite-State Machine (multiplatform)

Comachine Features Kotlin corutines. Event handlers can launch coroutines for collecting external events of performing side effects. Structured concur

Sergej Shafarenka 22 Dec 14, 2022
Kotlin coroutine capable Finite-State Machine (multiplatform)

Comachine Features Kotlin corutines. Event handlers can launch coroutines for collecting external events of performing side effects. Structured concur

Sergej Shafarenka 22 Dec 14, 2022
Skeleton project for show the architecture of Android project using MVVM, Clean Architecture and Kotlin coroutine Flow

ClearScoreDemo Skeleton project for showing the architecture of Android project using MVVM, Clean architecture and Kotlin coroutine Flow App Architect

Plabon Modak 1 Mar 6, 2022
Android application showcasing the MVVM architecture, Clean code using Kotlin, Coroutine, Flow and databinding.

Code4Lyst Android application showcasing the MVVM architecture, Clean code using Kotlin, Coroutine, Flow and databinding. App Architecture MVVM CleanC

Plabon Modak 1 Nov 29, 2021
A Gallery app developed using kotlin and MVVM architecture with Coroutine

A Gallery app developed using kotlin and MVVM architecture Loading image from un

Atiar Talukdar 1 Dec 21, 2021
Android - kotlin Coroutine with MVVM and Paging 3

Android - kotlin Coroutine with MVVM and Paging 3 To Loarn more about paging 3 To Loarn more about LoadStateAdapter API Reference Get all items Api So

Haresh 1 Mar 17, 2022
Coroutine for Bukkit

Heartbeat Coroutines 두근두근 ❤️ 코루틴 Coroutine for Paper Features Bukkit의 mainHeartBeat(GameLoop)에서 dispatch되는 Coroutine JavaPlugin 생명주기의 CoroutineScope 유

null 22 Dec 18, 2022
Android Clean Architechture with MVVM, LiveData, Coroutine, Dagger Hilt, Room, DataStore

MovKu An application that displays a list of popular movies and detail Concepts Tech Stack Kotlin -A modern programming language that makes developers

ꦤꦤꦁ​​ꦲꦫꦶꦥ꦳ꦸꦢꦶꦤ꧀ 3 Jul 29, 2022
🧸 A multiplatform coroutine-based wrapper for popular platform-specific Redis client libraries

?? rekt ⚠️ WARNING! This project is experimental and may be missing essential features. Please let us know if you found any issues or have any suggest

Hexalite Network 3 Aug 31, 2022
🧸 A multiplatform coroutine-based wrapper for popular platform-specific Redis client libraries

?? rekt ⚠️ WARNING! This project is experimental and may be missing essential features. Please let us know if you found any issues or have any suggest

Southdust Team 3 Aug 31, 2022