Hey guys. I’m currently working on the realm SDK m...
# realm
g
Hey guys. I’m currently working on the realm SDK migration from Java to Kotlin. In the migration docs there is this line:
Copy code
The Kotlin SDK does not provide the ability to set and access a default realm in your application. Since you can now share realms, objects, and results across threads, you can rely on a global singleton instead.
So I went with global singleton. But I don’t think this works like I thought it would (similar to room) as now I’m getting:
Copy code
java.lang.IllegalStateException: [RLM_ERR_WRONG_TRANSACTION_STATE]: The Realm is already in a write transaction
I have a background sync that might write at any given moment, should I open another Realm for that in this case to avoid this crash?
1
z
Easy to overlook is, that after calling realm.write {}, you shouldn't use the realm instance within the closure. Use 'this', which is a mutable Realm instance. Using the realm instance would result in the above error.
g
Yes that was my first thought, but it wasn’t that so I started panicking 😅 . I think it was caused by other write which failed with exception.
c
Yeah, we could probably improve the error message in cases like this.