我正在尝试从包中恢复我的应用程序(保存在Bundle中).
我的Activity使用OpenGL,因此它创建此表面视图并在保存或恢复应用程序时调用这些函数.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
在mRenderer
public void onRestoreInstanceState(Bundle inState){
mFlowManager = inState.getParcelable("flowmanager");
}
public void onSaveInstanceState (Bundle outState){
outState.putParcelable("flowmanager", mFlowManager);
}
Run Code Online (Sandbox Code Playgroud)
在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);
}
}
Run Code Online (Sandbox Code Playgroud)
FlowManager类具有需要保存的其他类的实例.那些我制作Parselable的类,而且在恢复它们时我得到了错误.
我已经看到有关此错误的帖子,但它们都是用于在应用程序之间发送数据并且必须使用不同的ClassLoader.这是所有相同的应用程序.我是否需要设置我的ClassLoader,因为它在GLSurfaceView中?我如何找到我需要的ClassLoader?
更新您FlowManager(Parcel in)的信息如下:
private FlowManager(Parcel in) {
mConnection = new Connection();
mState = State.valueOf(in.readString());
mSplash = in.readParcelable(SplashScreen.class.getClassLoader());
mMenu = in.readParcelable(MainMenu.class.getClassLoader());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1180 次 |
| 最近记录: |