Add RealmObject to a List without adding it to the Realm

1.2k views Asked by At

I know there are differences between managed RealmList and unmanaged RealmList. I don't get how I can decide whether my list is managed or not. I create the list as follow:
myList = new RealmList();
I populate the list as follow:
myList.add(item);
Every item I add to the RealmList is added to the Realm, and I don't want it because I'm developing a personal library of items and want the Realm to contain only items user needs in his library. Every item has a 'related' list in which I add other items (adding them to the realm too, even if I don't want to). Is there a way in which I could just add them to the RealmList without adding them to the Realm too?

1

There are 1 answers

6
Christian Melchior On

If you have the following code:

RealmList<Foo> myList = new RealmList(); myList.add(item);

Nothing is added to Realm. Adding items to Realm can only be done within a write transaction, so doing it outside one is a guarantee it is not persisted by Realm.