Cancel Async query
Goal
I have a problem to cancel an async query. My async query takes a little bit of time and I want to cancel it before I go into another Fragment. Otherwise, the database will be locked down until the original query has been finished. I tried to use removeChangeListener but it still lock down my other query.
Expected Results
Use removeChangeListener to release the database resources.
Actual Results
I cannot do another query until the original query has been finished.
Steps & Code to Reproduce
Describe your current debugging efforts.
Code Sample
Aysnc Query
mUnOrganizedContacts = getRealm().where(Contact.class)
.isEmpty("groupList.contacts")
.findAllAsync();
mUnOrganizedContacts.addChangeListener(new RealmChangeListener<RealmResults<Contact>>() {
@Override
public void onChange(RealmResults<Contact> contacts) {
num.setText("(" + String.valueOf(contacts.size()) + ")");
}
});
Remove Change listener
if(mUnOrganizedContacts != null)
mUnOrganizedContacts.removeAllChangeListeners();
Version of Realm and tooling
Realm version(s): ? 3.5.0 Realm sync feature enabled: yes/no
Android Studio version: ?
Which Android version and device: ?
what do you mean by "the database will be locked down until the original query has been finished."?
Hi there @cchuang6 ! Can you give us more information on this issue? We are, in particular, confused by the term "locked down". The Realm DB supports multiple concurrent modifications... -blake
Well modifications no, there can be only one write transaction across processes, but there should be no read lock during query execution either.
How much data do you have in terms of row count, 100000?
Totally my mistake. There can only be one write transaction across threads, of course.
The point I was trying to make is that queries should not, in any way, lock anything down. In fact, until you start trying to get values out of them they should be free...
@bmeike they are not 100% free because they need to become isLoaded() which takes time, but it still shouldn't block anything either.
Closing due to inactivity. @cchuang6 feel free to reopen if you have more information about this issue.