kmm-production-sample
kmm-production-sample copied to clipboard
Handle coroutine cancelation on Activity lifecycle callbacks
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).
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.
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.
Is there any example that implements this idea?
@Amrjyniat check my repo https://github.com/hoc081098/kmp-viewmodel/tree/master/sample
Sent from my 2201117TG using FastHub