Realm-java: Async query cannot be created on current thread. Realm cannot be automatically updated on an IntentService thread

Created on 23 Jul 2017  路  6Comments  路  Source: realm/realm-java

I want to update my default realm object from the intent service.

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.

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings