Reputation: 1593
Im using where clause in IntentService in android ,If I use the where clause the first 7 or 8 times it gives me the desired output but after certain time it fails and gives 0 for the result
Realm realm = Realm.getInstance(ApplicationController.getInstance().getRealmConfig(Constants.SCHEMA_LIVE));
RealmResults<RContactDTO> localContacts = realm.where(RContactDTO.class).equalTo("operationType", HttpOperation.PUT.name()).findAll();
Utils.Log("update contact count ::: " + localContacts.size(), Utils.LogType.DEBUG);
ArrayList<ContactDTO> contactList = new ArrayList<ContactDTO>();
RContactDTO rContactDTO = null;
for(RContactDTO rContact : localContacts){
contactList.add(new ContactDTO(rContact));
}
I have checked the actual data by exporting the realmDB.
Upvotes: 2
Views: 141
Reputation: 81588
In an IntentService, you're on a looper thread that doesn't loop. So that means your Realm cannot auto-update on an IntentService's thread, and it can't wait for changes either. So the workaround is to either use a normal thread and use waitForChange()
instead of an IntentService, or close the Realm when you no longer need it for an operation and then re-open it with getDefaultInstance()
.
Upvotes: 2
Reputation: 44
I had the same issue in Swift. Realm have some issue with auto refresh.
Use realm.refresh() before doing your clause.
Upvotes: 2