feresr feresr - 6 months ago 88
Android Question

RealmObject AND Parcelable

I'm new to Realm for Android so I'm not sure I'm approaching this the right way. I have a class which looks like this:

public class Entry extends RealmObject implements Parcelable {
...
}


The problem is the
Parcelable
interface contains methods like
describeContents()
writeToParcel()
and RealmObjects aren't supposed to have methods other than getters and setters:

Error:(81, 17) error: Only getters and setters should be defined in model classes


So my question is: How can I make these two work together? Is there a better way than creating an separate class (maybe something like
RealmEntry
)? Doing so would result in a lot of duplicated code...

Answer

Now there's a different workaround for that: just implement the RealmModel interface instead of extending from RealmObject:

@RealmClass
public class User implements RealmModel {

}

You can find more information in the Realm Documentation.