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

Handle coroutine cancelation on Activity lifecycle callbacks #48

Open
lukasz-kalnik-gcx opened this issue Nov 30, 2021 · 4 comments
Open

Comments

@lukasz-kalnik-gcx
Copy link

Support for canceling coroutines when Activity is destroyed is missing.
FeedStore has hardcoded CoroutineScope(Dispatchers.Main) which is not bound to any lifecycle callbacks.
This hardcoded coroutine scope also makes writing unit tests hard (it could be simply a constructor parameter).

@lukasz-kalnik-gcx lukasz-kalnik-gcx changed the title Handle cancelation on Activity lifecycle callbacks Handle coroutine cancelation on Activity lifecycle callbacks Nov 30, 2021
@terrakok
Copy link
Contributor

You are right. To inject CoroutineScope is good and right idea.
But for our case it doesn't matter because FeedStore lives with Application lifecycle. And will be destroyed with app process.
e.g. the FeedStore is needed not only for Activity but for background update service too.

@lukasz-kalnik-gcx
Copy link
Author

Ok, understand. Thank you for the explanation.
Then as a feature request it would be helpful to also have an example of a screen which is canceling a coroutine when it closes. This is a quite common use case and would be good to see some best practices how it can be done from Android and iOS side.

@Amrjyniat
Copy link

Is there any example that implements this idea?

@hoc081098
Copy link

@Amrjyniat check my repo https://github.com/hoc081098/kmp-viewmodel/tree/master/sample

Sent from my 2201117TG using FastHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants