OSDN Git Service

DO NOT MERGE Fix build with SDK 24-like implementation of constructor
authorAlan Viverette <alanv@google.com>
Tue, 13 Mar 2018 17:56:24 +0000 (13:56 -0400)
committerAlan Viverette <alanv@google.com>
Wed, 14 Mar 2018 15:22:10 +0000 (11:22 -0400)
Bug: 71992105
Test: manual
Change-Id: I106760ada9c85adde29fd143e5dfcd924fd95f54

core/java/com/android/internal/widget/ViewPager.java

index e4bb0cf..4634915 100644 (file)
@@ -1255,7 +1255,7 @@ public class ViewPager extends ViewGroup {
         };
 
         SavedState(Parcel in, ClassLoader loader) {
-            super(in, loader);
+            super(loadParcelable(in, loader));
             if (loader == null) {
                 loader = getClass().getClassLoader();
             }
@@ -1263,6 +1263,16 @@ public class ViewPager extends ViewGroup {
             adapterState = in.readParcelable(loader);
             this.loader = loader;
         }
+
+        /**
+         * Substitute for AbsSavedState two-arg constructor, which was added in
+         * SDK 24. Loads the super state from a given class loader or returns
+         * the empty state if null.
+         */
+        private static Parcelable loadParcelable(Parcel in, ClassLoader loader) {
+            Parcelable superState = in.readParcelable(loader);
+            return superState != null ? superState : AbsSavedState.EMPTY_STATE;
+        }
     }
 
     @Override