@@ -138,6 +138,22 @@ private void init() {
mMaximumVelocity = configuration. getScaledMaximumFlingVelocity();
}
+ @Override
+ protected Parcelable onSaveInstanceState () {
+ final SavedState state = new SavedState (super . onSaveInstanceState());
+ state. mCurrentScreen = mCurrentScreen;
+ return state;
+ }
+
+ @Override
+ protected void onRestoreInstanceState (Parcelable state ) {
+ SavedState savedState = (SavedState ) state;
+ super . onRestoreInstanceState(savedState. getSuperState());
+ if (savedState. mCurrentScreen != - 1 ) {
+ mCurrentScreen = savedState. mCurrentScreen;
+ }
+ }
+
@Override
protected void onMeasure (final int widthMeasureSpec , final int heightMeasureSpec ) {
super . onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -501,4 +517,36 @@ private void snapToScreen(final int whichScreen, final int duration) {
*/
void onScreenSwitched (int screen );
}
+
+ /**
+ * A parcelable so we can save our current screen and return to it after an activity destroy.
+ */
+ public static class SavedState extends BaseSavedState {
+ int mCurrentScreen = - 1 ;
+
+ SavedState (Parcelable superState ) {
+ super (superState);
+ }
+
+ private SavedState (Parcel in ) {
+ super (in);
+ mCurrentScreen = in. readInt();
+ }
+
+ @Override
+ public void writeToParcel (Parcel out , int flags ) {
+ super . writeToParcel(out, flags);
+ out. writeInt(mCurrentScreen);
+ }
+
+ public static final Parcelable . Creator<SavedState > CREATOR = new Parcelable .Creator<SavedState > () {
+ public SavedState createFromParcel (Parcel in ) {
+ return new SavedState (in);
+ }
+
+ public SavedState [] newArray (int size ) {
+ return new SavedState [size];
+ }
+ };
+ }
}
This comment has been minimized.
Show comment Hide commentysamlanJun 14, 2011
This code doesn't seem to actually work (try running the demo app and rotating the screen), on either the simple or tabbed examples. Can you confirm that the demos work for you with your patch?
ysamlan commented onJun 14, 2011
9c9df82
This code doesn't seem to actually work (try running the demo app and rotating the screen), on either the simple or tabbed examples. Can you confirm that the demos work for you with your patch?