Skip to main content

Questions tagged [kotlin-coroutines]

A language feature and a library introduced in Kotlin 1.3 that is used to implement the "green threads" model. It allows writing non-blocking IO code in a natural way, without resorting to futures or callbacks.

0 votes
0 answers
9 views

TestScope doesn't work in Kotlin Multiplatform

I was trying to run a unit test of my kmp code on android(local) with TestScope by injecting it into the view model. Here's the code: class FrankfurterRepository(engine: HttpClientEngine) { private ...
Yauheni Mokich's user avatar
2 votes
0 answers
45 views

Jetpack Compose CRUD application views don't refresh

I'm new to Android Compose. I'm generally teaching my daughter how to code and we decided to start with something that has an UI,so we chose Android to start. I made an app in Jetpack Compose and I ...
Piotr Klimaszewski's user avatar
0 votes
0 answers
10 views

Switch between account online and offline in android kotlin

I am student learning android application developing and now I want to develop application that I will make user online and offline I have API for both of them which I send user token to API. I make ...
mohamed hossam's user avatar
1 vote
0 answers
22 views

How Do You Pass A Function Into Foreground Services In Android Studio

I'm trying to create an application in Android Studio that consists of a timer that runs in the background. To achieve this I'm passing the timer functionality into a foreground service class. However,...
Bob Rasner's user avatar
0 votes
0 answers
25 views

Is it ok to call both joinAll() then awaitAll() on a list of coroutine jobs to enure my Android viewmodel waits for all jobs to complete?

My current android application has a strange bug associated with running multiple kotlin coroutine jobs to call back end json apis. initially I had the following code in an Android viewmodel:- val ...
Hector's user avatar
  • 4,846
1 vote
1 answer
42 views

I would like some help regarding an async between a compose navigation and a ViewModel update

I'm quite new to android kotlin and i have a little problem regarding my login. When i press the login button i immediately get directed to the home screen but before the ViewModel can be updated so i ...
nm16pc's user avatar
  • 15
1 vote
1 answer
36 views

Kotlin execution order mix with different scope and coroutines

I'm trying to figure out the order of the execution of coroutine. Here is my example. fun theCoroutineOrderWithDifferentScope() = runBlocking { coroutineScope { println("in the ...
Steven shih's user avatar
2 votes
1 answer
46 views

Kotlin coroutine context inherited by 'async' block

Please consider the following scenarios in which I'm using a ThreadLocal as a Kotlin coroutine context element. Scenario 1 - use withContext() to set the value of a ThreadLocal on an inner block: val ...
pedorro's user avatar
  • 3,239
1 vote
2 answers
42 views

What is the difference when we call withContext with coroutineContext and Job?

I am confused about working with withContext in Coroutine. I was calling withContext in a suspend function with the IO dispatcher. In that case, in some situations, the coroutine is canceled because ...
Niyas's user avatar
  • 757
-1 votes
0 answers
25 views

Is it recommended to implement StateFlow in a Custom Kotlin Flow class

I want to create a Custom Flow class which should be a Hot Flow. So it recommended to create something like below class ContentFlow(context: Context, initialValue: SomeObject) : StateFlow { ...
Maverick's user avatar
  • 372
1 vote
1 answer
30 views

Variable not updated in a Coroutine

I made a coroutine to update the value of a variable, but it doesn't work: fun findNameById(id: Long): String { var name = "" viewModelScope.launch(Dispatchers.IO) { val ...
Antonio Caravaggio's user avatar
0 votes
1 answer
33 views

How does Room DB with Flow works?

I’m experimenting with Room and Coroutines Flow observables in a simple project, but I'm encountering an issue where the Flow emits multiple times. In the app, I’m fetching all data from the user's ...
Ranpu's user avatar
  • 1
1 vote
1 answer
30 views

Ktor: launch long-running task then immediately send HTTP response

How do I properly launch a long-running task in Ktor sever without waiting for its completion, i.e. launch and immediately send the HTTP response back. In this answer: https://stackoverflow.com/a/...
Pete's user avatar
  • 51
0 votes
1 answer
53 views

how to fix this warning "GlobalScope, This is a delicate API and its use requires care"?

I'm currently learning how to build a Music App using compose and media3. onIsPlayingChanged(isPlaying: Boolean) in this method I'm using GlobalScope, Android studio give me this waring "This is ...
Fatima Jamal's user avatar
0 votes
0 answers
36 views

Crash | Can't access Looper on Coroutines Dispatchers.IO

I'm executing some tasks on Coroutines Dispatchers.IO like this to achieve concurrency: fun postMessage(request: Request) { CoroutineScope(Dispatchers.IO).launch { val requestHandler = ...
Ayush Gupta's user avatar

15 30 50 per page
1
2 3 4 5
315