Skip to content

fix: update flows when screen is visible#20192

Open
david-allison wants to merge 2 commits intoankidroid:mainfrom
david-allison:fix-flow-updates
Open

fix: update flows when screen is visible#20192
david-allison wants to merge 2 commits intoankidroid:mainfrom
david-allison:fix-flow-updates

Conversation

@david-allison
Copy link
Member

Purpose / Description

Knowing what I know now, repeatOnLifecycle(Lifecycle.State.STARTED) is better

Fixes

Approach

  • refactor to use context parameters
  • Change State.RESUMED => State.STARTED

How Has This Been Tested?

Unit tests: 1 fixed - the Robolectric runBlocking workaround wasn't perfect

I went through all seemingly risky functionality using my Pixel 9 Pro - no catastrophic issues.

Learning (optional, can help others)

Robolectric isn't perfect

Cause:

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

to 'Flow.kt' using context parameters
... but not interactive

Cause:
* https://redirect.github.com/ankidroid/Anki-Android/pull/17690#discussion_r1905349394
* => e35b5b9

Knowing what I know now,
`repeatOnLifecycle(Lifecycle.State.STARTED)` is better

Fixes 19632
@david-allison david-allison added this to the 2.24 release milestone Jan 22, 2026
Copy link
Contributor

@criticalAY criticalAY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question rest is all good, will approve once its resolved

activity.lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
this@launchCollectionInLifecycleScope.collect {
// on re-resume, an unchanged value will be emitted for a StateFlow
if (lastValue == value) return@collect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious and want to know what will happen if the app is in background and value is updated (lets say) lastValue check will see the new value when the app resumes, compare it to the new value property, and potentially skip the UI update.

@criticalAY criticalAY added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update flows when the screen is visible, but not interactive

2 participants

Comments