I want to update my default realm object from the intent service.
IntentService looper doesn't loop, so Realm cannot update it.
Only synchronous queries work, and only beginning a transaction or using Realm.refresh() will update the Realm.
I got the issue. But I want to do it from that service itself. How can i make it work?
I have edited my answer above.
Realm.getDefaultInstance().refresh();
pojo = RealmHelper.getInstance().getPojo(id);
if (pojo != null) {
RealmHelper.getInstance().saveOrUpdatePojo(pojo);
}
you mean this?
Ohh Got it, I was trying to query it asynchronously in the intent service. Thanks!
Every Realm.getDefaultInstance() call needs to be matched with a realm.close() call.
Otherwise Realm won't be closed on that thread. So Realm.getDefaultInstance().refresh() is bad idea.
Most helpful comment
IntentService looper doesn't loop, so Realm cannot update it.
Only synchronous queries work, and only beginning a transaction or using Realm.refresh() will update the Realm.