Closed kunalgharate closed 2 years ago
Please send me any projects where I can get the idea of how to pass data using MVVM to the realm
@realm-support I don't see any large projects on Github for complex data like filter data, sorting data, search data with any design pattern
@realmanalytics @RealmBot @realm
Hi @https://github.com/realm/realm-java/tree/master/examples/coroutinesExample could be one such example.
In your code sample, you just need to move the query inside the write transaction like this:
realm.executeTransactionAsync({
var residentUser = realm.where<ResidentUser>().equalTo("_id", ObjectId(id)).findFirst()
// You don't need this, just modify residentUser directly
realm.insertOrUpdate(residentUser)
}, {
Log.d(TAG, "updateResident: Updated item")
}, {
Log.d(TAG, "updateResident: ${it.localizedMessage}")
})
}
The reason you are getting the exception is that executeTransactionAsync()
runs on a separate thread, so using Realm data outside that thread will throw. I would recommend this article for a deeper explanation: https://academy.realm.io/posts/threading-deep-dive/
Hello team ,
working on the realm for the project but I have multiple fragments where I have inserting data and updating same the data. I am using the realm data source class which I got in OFishWild - An open source project developed by MongoDB Team but when I updating the data its throwing the error accessing on an incorrect thread.
Step of update :
fun getResidentDetails(id: String): ResidentUser? { if (id.isBlank()) return null return realm.where().equalTo("_id", ObjectId(id)).findFirst()
}
fun updateResident(_residentUser: ResidentUser , id: String) {
https://github.com/WildAid/o-fish-android/blob/main/app/src/main/java/org/wildaid/ofish/data/RealmDataSource.kt