Fragment OnSavedInstanceSate and Realm
<p>I am using Realm as database for my android app, I got a fragment which has a RealmList of objects, let’s say ‘X’of type.  And also this fragment contains a view pager.  Each child fragments contains a ListView. Main fragment sends an X object from RealmList per child fragment.</p>

<p>X class contains a RealmList that contains ‘Z’ type objects. ListView component in each child fragment shows ‘Z’ class information in each row.
When I am come in to the main fragment at run time, everything is worked fine. But if I press home button of the device to escape from the app for a while, App get crashed by throwing following exception.</p>

<pre><code>java.lang.RuntimeException: Parcelable encountered IOException writing 
serializable object (name = io.realm.XRealmProxy)
at android.os.Parcel.writeSerializable(Parcel.java:1323)
at android.os.Parcel.writeValue(Parcel.java:1271)
............

Caused by: java.io.NotSerializableException: io.realm.XRealmProxy$XColumnInfo
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1366)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
</code></pre>

<p>After spending 3 hours in googling. I got that each RealmObject maintains a proxy class in background and It is not a serializable object. So I can understand that the fragment is trying to reach the on saved instance state, due to unserializeble it throws it.
As the android doc says, when an activity or fragment going to onSavedInstance state it preserve only information about its view. </p>

<p>My question is, then why it trying to preserve  RealmList.</p>

<p>And any solution to solve this.
I tried to override the OnSavedInstance method and make RealmList field null. But it won’t work.</p>

<p><a href="http://developer.android.com/training/basics/activity-lifecycle/recreating.html" rel="nofollow">Android doc</a></p>

<p><a href="https://github.com/realm/realm-java/issues/1903" rel="nofollow">Similer question</a></p>