fix: update flows when screen is visible#20192
Open
david-allison wants to merge 2 commits intoankidroid:mainfrom
Open
fix: update flows when screen is visible#20192david-allison wants to merge 2 commits intoankidroid:mainfrom
david-allison wants to merge 2 commits intoankidroid:mainfrom
Conversation
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
criticalAY
reviewed
Feb 5, 2026
Contributor
criticalAY
left a comment
There was a problem hiding this comment.
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 |
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose / Description
Knowing what I know now,
repeatOnLifecycle(Lifecycle.State.STARTED)is betterFixes
Approach
State.RESUMED=>State.STARTEDHow Has This Been Tested?
Unit tests: 1 fixed - the Robolectric
runBlockingworkaround wasn't perfectI 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