I am trying to restore my application from a Parcel (saved in a Bundle).
My Activity uses OpenGL so it creates this surface view and calls these functions when it is saving or restoring the app.
class MySurfaceView extends GLSurfaceView {
/* Lots of other stuff */
public void onRestoreInstanceState(Bundle inState) {
Log.d("Wormhole", "Restoring instance state");
mRenderer.onRestoreInstanceState(inState);
}
public void onSaveInstanceState(Bundle outState) {
Log.d("Wormhole", "Saving instance state");
mRenderer.onSaveInstanceState(outState);
}
}
in mRenderer
public void onRestoreInstanceState(Bundle inState){
mFlowManager = inState.getParcelable("flowmanager");
}
public void onSaveInstanceState (Bundle outState){
outState.putParcelable("flowmanager", mFlowManager);
}
in mFlowManager
public class FlowManager implements Touchable, Parcelable {
private enum State {
SPLASH, MENU, GAME_SINGLE, GAME_MULTI
};
private Connection mConnection;
private ScoreDataSource mScoreDataSource;
private GameEngine mGameEngine;
private SplashScreen mSplash;
private MainMenu mMenu;
private State mState = State.SPLASH;
private long mTime;
private int mVersionID;
/* Other stuff */
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(mState.name());
out.writeParcelable(mSplash, 0);
out.writeParcelable(mMenu, 0);
}
public static final Parcelable.Creator<FlowManager> CREATOR = new Parcelable.Creator<FlowManager>() {
public FlowManager createFromParcel(Parcel in) {
return new FlowManager(in);
}
public FlowManager[] newArray(int size) {
return new FlowManager[size];
}
};
private FlowManager(Parcel in) {
mConnection = new Connection();
mState = State.valueOf(in.readString());
mSplash = in.readParcelable(null); // Exception occurs here
mMenu = in.readParcelable(null);
}
}
The FlowManager class has instances of other classes that need to be saved. Those classes I made Parselable and it’s when restoring them I get the error.
I’ve seen posts about this error but they all were for sending data between apps and having to use a different ClassLoader. This is all the same app. Do I need to set my ClassLoader because this is in a GLSurfaceView? How do I find the ClassLoader I need?
update your
FlowManager(Parcel in)as below: