title: Save custom object array in instance state
body: <p>I have a <code>List&lt;CustomObject&gt;</code> (where <code>CustomObject</code> comes from an external library -- I can't make changes to it). I want to save this in <code>onSaveInstanceState(Bundle)</code>, but I can't seem to do it. Here are the options that I've tried:</p>
  
  <pre><code>outState.putSerializable(KEY, (ArrayList&lt;CustomObject&gt;) myList); // because myList is instantiated as an ArrayList
  outState.putSerializable(KEY, myList.toArray());
  </code></pre>
  
  <p>Both options <strong>work</strong> when switching orientation on the phone (yes, <code>onSaveInstanceState</code> is called when switching orientation -- I checked in logcat). However, when the current activity tries to start another one (with <code>startActivity(Intent)</code>), Android pauses the current activity and calls <code>onSaveInstanceState()</code> again. This time, it fails, for some reason unknown to me. The fishy thing is that <code>onSaveInstanceState()</code> executes successfully. The stack trace printed doesn't point to any of my code:</p>
  
  <pre><code>E/AndroidRuntime(23898): java.lang.RuntimeException: Parcel: unable to marshal value my.custom.Object@5e07e43b
  E/AndroidRuntime(23898):    at android.os.Parcel.writeValue(Parcel.java:1087)
  E/AndroidRuntime(23898):    at android.os.Parcel.writeArray(Parcel.java:519)
  E/AndroidRuntime(23898):    at android.os.Parcel.writeValue(Parcel.java:1072)
  E/AndroidRuntime(23898):    at android.os.Parcel.writeMapInternal(Parcel.java:469)
  E/AndroidRuntime(23898):    at android.os.Bundle.writeToParcel(Bundle.java:1445)
  E/AndroidRuntime(23898):    at android.os.Parcel.writeBundle(Parcel.java:483)
  E/AndroidRuntime(23898):    at android.app.ActivityManagerProxy.activityPaused(ActivityManagerNative.java:1427)
  E/AndroidRuntime(23898):    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3106)
  E/AndroidRuntime(23898):    at android.app.ActivityThread.access$2400(ActivityThread.java:119)
  E/AndroidRuntime(23898):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
  E/AndroidRuntime(23898):    at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime(23898):    at android.os.Looper.loop(Looper.java:123)
  E/AndroidRuntime(23898):    at android.app.ActivityThread.main(ActivityThread.java:4363)
  E/AndroidRuntime(23898):    at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime(23898):    at java.lang.reflect.Method.invoke(Method.java:521)
  E/AndroidRuntime(23898):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  E/AndroidRuntime(23898):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  E/AndroidRuntime(23898):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Is there any way to store custom objects in the instance state?</p>