I'm developing an android application in which fragments use dynamically created views. Part of my onSaveInstanceState()
method in my fragment is as follows:
outState.putSerializable("intToRow", (HashMap<Integer, View>) intToRow);
When I comment out this line everything works fine. I've left this line in for now and here's the problem:
When I rotate the screen, this works fine and I can access it in onCreate()
using
intToRow = (HashMap) savedInstanceState.getSerializable("intToRow");
And when the back button on the action bar is pressed the fragment and activity close without any problems. So why is it that when I press the Home button or the multitasking button, the app crashes? The stack trace is:
java.lang.RuntimeException: Parcel: unable to marshal value android.widget.TextView{383ee509 V.ED.... ........ 246,0-492,57 #3}
at android.os.Parcel.writeValue(Parcel.java:1337)
at android.os.Parcel.writeMapInternal(Parcel.java:614)
at android.os.Parcel.writeMap(Parcel.java:598)
at android.os.Parcel.writeValue(Parcel.java:1255)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.FragmentState.writeToParcel(Fragment.java:147)
at android.os.Parcel.writeTypedArray(Parcel.java:1191)
at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:380)
at android.os.Parcel.writeParcelable(Parcel.java:1357)
at android.os.Parcel.writeValue(Parcel.java:1262)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3116)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3695)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
I've seen many questions about the whole Parcel: unable to marshal value
error but mine doesn't seem to match any of them. In my app, an orientation change and destroying the fragment seem to work perfectly but pressing the Home button makes it crash. I've been through the Android lifecycle but I can't see anything that should happen when Home is pressed that wouldn't happen otherwise.