diff options
| author | Adam Powell <adamp@google.com> | 2013-06-13 17:44:04 -0700 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2013-06-13 17:44:04 -0700 |
| commit | 90f339a5a343f82c3c32e4467c54ded94a1807a1 (patch) | |
| tree | 99b59625a11b1a7fa93b1263faf95770f42fbac3 /core/java/android/widget/ScrollView.java | |
| parent | 256a5f8cda213969d9ae577a13427b4ae371ea61 (diff) | |
Don't save ScrollView/HorizontalScrollView saved state for old apps
Older apps may have given IDs to ScrollViews and views of a different
class in layouts that vary by configuration. Now that ScrollViews save
state this causes ClassCastExceptions when trying to restore instance
state.
Only save new instance state for ScrollView/HorizontalScrollView for
apps targeting post-API 18.
Change-Id: Icaa095cd20bef35dddc225a17c5a8e30b3faea02
Diffstat (limited to 'core/java/android/widget/ScrollView.java')
| -rw-r--r-- | core/java/android/widget/ScrollView.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index b764c98843fb..b32cfbc04604 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -16,6 +16,7 @@ package android.widget; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.R; @@ -1662,6 +1663,12 @@ public class ScrollView extends FrameLayout { @Override protected void onRestoreInstanceState(Parcelable state) { + if (mContext.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.JELLY_BEAN_MR2) { + // Some old apps reused IDs in ways they shouldn't have. + // Don't break them, but they don't get scroll state restoration. + super.onRestoreInstanceState(state); + return; + } SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); mSavedState = ss; @@ -1670,6 +1677,11 @@ public class ScrollView extends FrameLayout { @Override protected Parcelable onSaveInstanceState() { + if (mContext.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.JELLY_BEAN_MR2) { + // Some old apps reused IDs in ways they shouldn't have. + // Don't break them, but they don't get scroll state restoration. + return super.onSaveInstanceState(); + } Parcelable superState = super.onSaveInstanceState(); SavedState ss = new SavedState(superState); ss.scrollPosition = mScrollY; |
