For below v10 realm android users. Given below will work fine
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<Note> result = realm.where(Notes.class).equalTo(Note.NOTE_ID,noteID).findAll();
result.deleteAllFromRealm();
}
});
However, it will crash for v10 and above
Running transactions on the UI thread has been disabled.
Your app will not crash if you run execute transactions from the UI thread as long as you are running Realm prior to v10. For the upcoming v10 release we are introducing two new settings in RealmConfiguration.Builder
, namely allowWritesOnUiThread
and allowQueriesOnUiThread
, which will allow users to control whether it is allowed to run transactions and/or queries from the UI thread.
RealmConfiguration config = new RealmConfiguration.Builder()
.allowWritesOnUiThread(true)
.build()
And it will work like it always has. So you can decide when/if you want to opt into the new behavior.