Last active
July 11, 2017 10:55
-
-
Save Zhuinden/d6c5fb007b3c725e2c9625244d8d0daa to your computer and use it in GitHub Desktop.
Open RealmResults in transaction, not outside of it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try(Realm realm = Realm.getDefaultInstance()) { | |
final RealmResults<Dog> dogs = realm.where(Dog.class).findAll(); // NO | |
realm.executeTransaction(inRealm -> { // NO | |
for(Dog dog : dogs) { // NO | |
//... | |
} | |
}); | |
} | |
//////////////////// | |
try(Realm realm = Realm.getDefaultInstance()) { | |
realm.executeTransaction(inRealm -> { // YES | |
final RealmResults<Dog> dogs = inRealm.where(Dog.class).findAll(); // YES | |
for(Dog dog : dogs) { // YES (0.89.0+) | |
//... | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment