RealmObject AND Parcelable

UPDATE May 2016: This is answer is now out-dated unless you already use Parceler. @Henrique de Sousa's solution is much better.


Actually, there is a workaround. You can get the result you want if you're willing to use a third-party library (Parceler) for Parcelable generation. See my answer to this other question, quoted below for convenience.

With Parceler v0.2.16, you can do this:

@RealmClass      // required if using JDK 1.6 (unrelated to Parceler issue)
@Parcel(value = Parcel.Serialization.BEAN, analyze = { Feed.class })
public class Feed extends RealmObject {
    // ...
}

Then, use Parcels.wrap(Feed.class, feed) instead of Parcels.wrap(feed) everywhere, otherwise your app will crash with org.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.FeedRealmProxy.


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.