Reputation: 768
I have two threads which don't work with UI thread. In one thread I receive JSON from server and save it to Realm DB :
Realm realm = Realm.getDefaultInstance();
final RealmResults<MyClass> all = realm.where(MyClass.class).findAll();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
all.deleteAllFromRealm();
realm.createOrUpdateAllFromJson(MyClass.class, recommendations);
}
});
realm.close();
Then, in another thread after interaction with user I need to acquire this information, but it is unavailable :
Realm realm = Realm.getDefaultInstance();
RealmResults<MyClass> responseItems = realm.where(MyClass.class).findAll();
realm.close();
So when I acquire data on the thread where I added them I can see them, on other threads they are unavailable. How can I merge information on different threads or notify instances to Update ?
Using : io.realm:realm-gradle-plugin:1.0.0
UPDATE : Information from different tables merges after application restart.
Upvotes: 1
Views: 1452
Reputation: 768
I found a workaround - even if I don't need any transaction I call .beginTransaction() before call where(clazz.class) and data is up to date.
Upvotes: 3