Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

0 votes
0 answers
26 views

How to prevent a SharedFlow collect values when the activity resumes?

I have found an issue where SharedFlow does not collect values when the activity is open. So I set replay = 1, which worked fine initially. However, I found that when the app is sent to the background ...
Tawanp's user avatar
  • 1
2 votes
2 answers
48 views

Puzzling Coroutines behavior in Android ViewModel

I am trying to explore and implement coroutine cancellation / exception recovery mechanism in ViewModel. I discovered that the following code in my ViewModel doesn't catch the exception and crashes ...
Shyam Patel's user avatar
0 votes
1 answer
24 views

Flow doesn't emit in test when using Dispatchers.Main.immediate (or viewModelScope) to change the value of a StateFlow

I investigated for hours and searched the web (and even bothered ChatGPT) and I'm puzzled this hasn't been solved yet to my (obviously very limited) knowledge. So this is the setup: I have a view ...
nepa's user avatar
  • 1,452
0 votes
2 answers
50 views

Timer Increments By One Whenever User Tries To Reset It Back To Zero In Android

I made a standard stopwatch app in Android Studio using jetpack compose. It gives the user the ability to reset the stopwatch back to zero, however there is a problem. The stopwatch will reset back to ...
Bob Rasner's user avatar
-1 votes
1 answer
54 views

Does the delay function compensate for the time the system suspend?

When calling delay() in android using Kotlin and a system suspend occurs before the timeout, does the delay() time actually get longer? For example, when I call delay(10.minutes) at exactly 10:00, but ...
progquester's user avatar
  • 1,557
2 votes
2 answers
40 views

Unable to create updated UI with new image in JetPack Compose

I'm trying to create simple Dice Roller JetPack Compose App. I create an Image compose and button compose. Whenever I click on the button, log statement shows button is clicked but I'm unable to ...
Aamir Khan's user avatar
0 votes
0 answers
10 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
52 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
1 vote
1 answer
43 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
  • 25
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
47 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,249
1 vote
2 answers
44 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
26 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
31 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
40 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

15 30 50 per page
1
2 3 4 5
269