4
votes

Is there any way or pattern to know/check at which thread a realm object was created? i.e. any way to know in advance if accessing realm object from current thread will throw "java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created."?

1

1 Answers

1
votes

No, there is not, but in general you shouldn't send RealmObjects to methods that work on other threads. Instead send the primary key and refetch or use the realm.copyFromRealm() method. The first is much preferable though.

You can read more about the threading model here: https://realm.io/docs/java/latest/#threading