Search code examples
realm

Use case example for copyToRealm() in Realm


Could someone give a simple use case example why someone would use copyToRealm() instead of createObject() ?

It is not clear to me why and when would anyone use copyToRealm() if there is createObject().

In the example here they seem pretty much the same https://realm.io/docs/java/latest/ .

copyToRealm() takes an unmanaged object and connects it to a Realm, while createObject() creates an object directly in a Realm.


Solution

  • For example it is very useful when you copy objects generated by GSON - returned from your Rest API into Realm.