Hi all, I have a weird bug with CMP and Room. I ha...
# compose
a
Hi all, I have a weird bug with CMP and Room. I have two screens A and B. ViewModelA is subscribed to a room table through flow on init. After starting the app i go to screen B, modify the table, go back to screen A, everything works as expected A reacts to changes in the table done in B. Now that stops working after screen rotation. I worked around it by recollecting on rotation, but this is weird since vm is the same and initial collection job is active and fine. Does anyone have an idea?
s
It's a bit hard to guess without seeing what you're actually doing. Can you make a simple reproducer? I'm guessing hitting back re-uses the same observer, rotating causes a configuration change which means you recreate the observer in your UI code, and however you're doing things in the VM fails with the second observer.
Ah, found the issue, it was about Dependency Injection setup, the two viewmodels where supposed to use the same singleton as dependency, but the singleton was not a singleton, was a new instance on rotation.
s
Ah, makes sense. DI can complicate things. I couldn't find anything just by reading.