NotSerializableException when pressing home button
<p>I have an <code>Activity</code> in which I have a private class Data.
In the <code>onSaveInstanceState</code> method, I try to save this an instance of <code>Data</code>.
This is my whole Activity: </p>

<pre><code>public class TestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public void onSaveInstanceState(Bundle outState){
        outState.putSerializable("TEST", new Data());
    }

    private class Data implements Serializable {

        private static final long serialVersionUID = -4312723541994925110L;

    }
}
</code></pre>

<p>Now when I change the orientation of the device, the <code>Data</code> object is saved and read as it should. However, when I press the home button, the app crashes with the following in the logcat:</p>

<blockquote>
  <p>05-10 20:05:51.895: E/AndroidRuntime(30317): FATAL EXCEPTION: main
  05-10 20:05:51.895: E/AndroidRuntime(30317):
  java.lang.RuntimeException: Parcelable encountered IOException writing
  serializable object (name = com.rigidbits.test.TestActivity$Data)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  android.os.Parcel.writeSerializable(Parcel.java:1176) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    at
  android.os.Parcel.writeValue(Parcel.java:1130) 05-10 20:05:51.895:
  E/AndroidRuntime(30317):  at
  android.os.Parcel.writeMapInternal(Parcel.java:488) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    at
  android.os.Bundle.writeToParcel(Bundle.java:1552) 05-10 20:05:51.895:
  E/AndroidRuntime(30317):  at
  android.os.Parcel.writeBundle(Parcel.java:502) 05-10 20:05:51.895:
  E/AndroidRuntime(30317):  at
  android.app.ActivityManagerProxy.activityPaused(ActivityManagerNative.java:1615)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2298)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  android.app.ActivityThread.access$1700(ActivityThread.java:117) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    at
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:938)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  android.os.Handler.dispatchMessage(Handler.java:99) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    at
  android.os.Looper.loop(Looper.java:130) 05-10 20:05:51.895:
  E/AndroidRuntime(30317):  at
  android.app.ActivityThread.main(ActivityThread.java:3683) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    at
  java.lang.reflect.Method.invokeNative(Native Method) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    at
  java.lang.reflect.Method.invoke(Method.java:507) 05-10 20:05:51.895:
  E/AndroidRuntime(30317):  at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    at
  dalvik.system.NativeStart.main(Native Method) 05-10 20:05:51.895:
  E/AndroidRuntime(30317): Caused by: java.io.NotSerializableException:
  com.rigidbits.test.TestActivity 05-10 20:05:51.895:
  E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1535)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
  05-10 20:05:51.895: E/AndroidRuntime(30317):  at
  android.os.Parcel.writeSerializable(Parcel.java:1171) 05-10
  20:05:51.895: E/AndroidRuntime(30317):    ... 16 more</p>
</blockquote>

<p>When I comment the line in the <code>onSaveInstanceState</code> method so the <code>Data</code> object is <em>not</em> saved, the app disappears correctly.</p>

<p>Any help with this?</p>
