Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Fatal Exception (NotSerializableException) when quitting an activity that serializes objects in onSave/onRecall
    text
    copied!<p>I am developing an app that uses some custom classes as members. I have implemented serialization/de-serialization in the onSaveInstanceState and onRestoreInstanceState methods. </p> <p>It all works fine when rotating the screen (app is destroyed and re-created) and my objects are restored. However, when pressing the home button, the app crashes in the onPause method (which I have not modified)...</p> <p>Any clue as to what's happening?</p> <p>Here's a code sample that reproduces the issue</p> <pre><code>import java.io.Serializable; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class InvestigateError extends Activity { private static final String LOG_TAG = "MYERROR"; protected ShowInfo myShowInfo; protected class ShowInfo implements Serializable { private static final long serialVersionUID = 1L; public String title; } public void populateMembers() { myShowInfo = new ShowInfo(); myShowInfo.title = "Was I serialized???"; } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); if(savedInstanceState == null) populateMembers(); Log.d(LOG_TAG,"Activity created"); } /* Save members */ @Override public void onSaveInstanceState(Bundle outState) { Log.d(LOG_TAG,"__ SAVEINSTANCE __"); outState.putSerializable("myshowInfo", myShowInfo); super.onSaveInstanceState(outState); } /* Restore members */ @Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); Log.d(LOG_TAG,"__ RECALLINSTANCE __"); myShowInfo = (ShowInfo) savedInstanceState.getSerializable("myshowInfo"); Log.d(LOG_TAG,"string from object: " + myShowInfo.title); } @Override protected void onDestroy() { Log.d(LOG_TAG,"__ DESTROY __"); super.onDestroy(); } @Override protected void onPause() { Log.d(LOG_TAG,"__ PAUSE __"); super.onPause(); } @Override protected void onStop() { Log.d(LOG_TAG,"__ STOP __"); super.onStop(); } } </code></pre> <p>Here's the beginning of the stack trace</p> <blockquote> <p>java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.esquared.InvestigateError.InvestigateError$ShowInfo)</p> <blockquote> <p>at android.os.Parcel.writeSerializable(Parcel.java:1160)</p> <p>at ndroid.os.Parcel.writeValue(Parcel.java:1114)</p> <p>at android.os.Parcel.writeMapInternal(Parcel.java:479)</p> <p>...</p> </blockquote> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload