Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

android - Nested Realm list inside real object not updating

I have a Realm object called SampleRO which have a field of type RealmList of DataRO Realm object type in it:

open class SampleRO(

    @PrimaryKey
    var id: Int = 0,
    @Required
    var title: String = "",
    var polls: RealmList<DataRO> = RealmList()
) : RealmObject()

open class DataRO(
    @PrimaryKey
    var id: Int = 0,
    @Required
    var text: String = "",
    var subText: String? = null,
    var isSelected: Boolean? = null,
    var percentage: Int? = null,
    var imageUrl: String? = null,
    var noVotes: Int? = null
) : RealmObject()

I try to update the data like this,

 Realm.getDefaultInstance().use { realm ->
    realm.executeTransaction { localRealm ->
        localRealm.copyToRealmOrUpdate(samplesRO)
    }
 }

Now whenever I sync my database with server, the api return updated values in DataRO object which ultimately returned inside SampleRO object. But what happens is sometime the DataRO object data didn't get updated and copyToRealmOrUpdate method returns the old DataRO object list.

I don't know why this happens because this happens randomly. I have searched al over the internet but nothing seems to be found helpful.

Please help if someone knows the cause of the issue.

question from:https://stackoverflow.com/questions/65952229/nested-realm-list-inside-real-object-not-updating

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...