I am seeing the following error in my Android crash reports:
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v4.view.ViewPager$SavedState at android.os.Parcel.readParcelable(Parcel.java:1971) at android.os.Parcel.readValue(Parcel.java:1859) at android.os.Parcel.readSparseArrayInternal(Parcel.java:2128) at android.os.Parcel.readSparseArray(Parcel.java:1581) at android.os.Parcel.readValue(Parcel.java:1916) at android.os.Parcel.readMapInternal(Parcel.java:2099) at android.os.Bundle.unparcel(Bundle.java:223) at android.os.Bundle.getSparseParcelableArray(Bundle.java:1225) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:806) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431) at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:160) at android.support.v4.view.ViewPager.populate(ViewPager.java:895) at android.support.v4.view.ViewPager.populate(ViewPager.java:772) at android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1539) at android.support.v4.view.ViewPager.computeScroll(ViewPager.java:1422) at android.view.ViewGroup.drawChild(ViewGroup.java:3028) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788) at android.view.ViewGroup.drawChild(ViewGroup.java:3184) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788) at android.view.ViewGroup.drawChild(ViewGroup.java:3184) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788) at android.view.ViewGroup.drawChild(ViewGroup.java:3184) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788) at android.view.View.draw(View.java:11017) at android.widget.FrameLayout.draw(FrameLayout.java:450) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2175) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2234) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1810) at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2695) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:4977) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method)
It appears to happen intermittently when resuming an activity. I do not directly access the SavedState class in any code.
I had the same error and here is what I did.
My issue came from using the ViewPager with a FragmentStatePagerAdapter. Inside one of the Fragments from the ViewPager had another ViewPager. Having that second view pager caused this rare bug. Even with or without an adapter on it.
The solution was to simply set setSaveEnabled(false); on the second ViewPager.
Following solution worked for me:
package android.support.v4.app; import android.os.Bundle; import android.view.ViewGroup; public abstract class FixedFragmentStatePagerAdapter extends FragmentStatePagerAdapter { public FixedFragmentStatePagerAdapter(FragmentManager fm) { super(fm); } @Override public Object instantiateItem(ViewGroup container, int position) { Fragment f = (Fragment)super.instantiateItem(container, position); Bundle savedFragmentState = f.mSavedFragmentState; if (savedFragmentState != null) { savedFragmentState.setClassLoader(f.getClass().getClassLoader()); } return f; } }
from http://code.google.com/p/android/issues/detail?id=37484#c1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With