I’m warking on an Android app using Realm, and I want to actively observe the data I have on the Realm DB through Kotlin Flows. I have been doing that like this:
However, I’m seeing more often crashes related to “Cannot modify managed objects outside of a write transaction.” – is there any way to prevent that? should I be freezing these objects or doing something else?
Thanks! Is there a way to make sure I completely unhook the objects from Realm so I don’t run into these issues. I started doing a:
.map { realm.copyFromRealm(it) }
and I think it might have got rid of the issue, but IDK if it is enough, is there something else that I should be doing? should I also make sure that the object is managed before doing the copy?
copyFromRealm would help avoid the issue, it creates a copy of the data, so any further modifications would not be persisted thus not require to be within a transaction.