LaunchedEffect not restarted after backgrounding Circuit app #2275
itsandreramon
started this conversation in
General
Replies: 1 comment
-
The It's a little hard to know what could be wrong without knowing what |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Moved this into discussions as requested:
I ran into an edge-case lately that involves backgrounding and foregrounding a Circuit app I've been developing. Basically what happens is that I have a Presenter that uses LaunchedEffect (or in our case RememberedEffect which is the same as LaunchedEffect but without a coroutine attached) to start Interactors. In our case we have a SubjectInteractor which allows me to observe a list of items from local storage. To avoid restarting in compositions we internally use a ParamStateFlow with distinctUntilChanged similar to what Tivi is using. Although I don't think it has to do with the issue I will just leave the code here:
The presenter injects them like this:
So when entering the screen, the LaunchedEffect kicks off the SubjectInteractor and we get updates that we can show in Ui. Backgrounding the app and foregrounding again causes the LaunchedEffect to not restart with Unit as a key. This causes the tasksResource to not be updated. The presenter is recreated (e.g. new UiComponent etc.) and our App composable is restarted properly. We could fix this issue by just passing hashCode of the Presenter class as key but this feels like a workaround.
Beta Was this translation helpful? Give feedback.
All reactions