Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace calls to launchWhenResumed with repeatOnLifecycle #7722

Closed
bmarty opened this issue Dec 6, 2022 · 0 comments · Fixed by #7724
Closed

Replace calls to launchWhenResumed with repeatOnLifecycle #7722

bmarty opened this issue Dec 6, 2022 · 0 comments · Fixed by #7724
Assignees
Labels
T-Task Refactoring, enabling or disabling functionality, other engineering tasks

Comments

@bmarty
Copy link
Member

bmarty commented Dec 6, 2022

launchWhenResumed is not recommended and will be removed in the future.
We should instead use repeatOnLifecycle

Exemple:

 lifecycleScope.launch {
                lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
                    flow.collect { flowItem ->
                        //DoSomethingWithFlowItem(flowItem
                    }
                }
            }

We might also be safer with listening viewEvents flow from ViewModel, to avoid refreshing UI if the app is in background:
So replace:

viewEvents
                .stream()
                .onEach {
                    hideWaitingView()
                    observer(it)
                }
                .launchIn(lifecycleScope)

By:

lifecycleScope.launch { 
            repeatOnLifecycle(Lifecycle.State.RESUMED){
                viewEvents.stream()
                        .collect {
                            hideWaitingView()
                            observer(it)
                        }
            }
        }
@bmarty bmarty added the T-Task Refactoring, enabling or disabling functionality, other engineering tasks label Dec 6, 2022
@bmarty bmarty self-assigned this Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Refactoring, enabling or disabling functionality, other engineering tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant