I have been noticing that when I have updated an object recently of a certain class and I try to fetch a list of those objects, the most recently updated object is returned with wrong values.
It is not happening every time but it happens every once in a while.
The data gets correctly inserted in the RealmDB.
I am using the following code snippet to fetch from realm.
public static <T extends RealmModel> ArrayList<T> fetchAllForKey(Class<T> clazz, String key, boolean value) {
Realm realm = Realm.getInstance(new RealmConfiguration.Builder().build());
RealmQuery query = realm.where(clazz);
query.equalTo(key, value);
RealmResults<T> results = query.findAll();
ArrayList<T> list = realm.copyFromRealm(realmResults);
realm.close;
return list;
}
I have 5 Objects in the RealmDB and when I fetch using the above function I get a list of size 5 but sometimes it returns a list of 4 size even when I have the data in DB and on the subsequent fetch it returns list of size 5.
I am trying to figure out why realm is returning wrong values and a way to mitigate this.