Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onRestoreInstanceState error #6

Open
RoelRoel opened this issue Feb 9, 2016 · 1 comment
Open

onRestoreInstanceState error #6

RoelRoel opened this issue Feb 9, 2016 · 1 comment

Comments

@RoelRoel
Copy link

RoelRoel commented Feb 9, 2016

  /**
   * Called when Android restores the activity.
   */
  @Override
  protected void onRestoreInstanceState(Parcelable state) {
    if (state == null || !state.getClass().equals(SavedState.class)) {
      super.onRestoreInstanceState(state);
      setTheDate(((SavedState) state).dateValue);
    } else {
      SavedState s = (SavedState) state;
      super.onRestoreInstanceState(s.getSuperState());
      setTheDate(s.dateValue);
    }
  }

This gives java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to org.bostonandroid.datepreference.DatePreference$SavedState
at line 3 of the funciton (setTheDate(((SavedState) state).dateValue);)

@RoelRoel RoelRoel changed the title onRestoreInstanceState is not logical onRestoreInstanceState error Feb 9, 2016
@hgoebl
Copy link

hgoebl commented May 14, 2016

I get the same error when rotating Activity with Fragment containing DatePreference.

I'm trying to run with following code (unfortunately I don't fully understand the reason for creating the class SavedState when there is only one attribute and why there is different handling when isPersistent() is true). This is only a blind try...

  protected void onRestoreInstanceState(Parcelable state) {
    if (state instanceof SavedState) {
      SavedState s = (SavedState) state;
      super.onRestoreInstanceState(s.getSuperState());
      setTheDate(s.dateValue);
    } else {
      super.onRestoreInstanceState(state);
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants