我正在使用带有PagerAdapter的自定义视图寻呼机,当我有"不要保持活动时,我会遇到以下崩溃问题。打开了:
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v4.view.ViewPager$SavedState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v4.view.ViewPager$SavedState
at android.os.Parcel.readParcelableCreator(Parcel.java:2432)
at android.os.Parcel.readParcelable(Parcel.java:2358)
at android.os.Parcel.readValue(Parcel.java:2264)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2675)
at android.os.Parcel.readSparseArray(Parcel.java:1967)
at android.os.Parcel.readValue(Parcel.java:2321)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2614)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getBundle(Bundle.java:763)
at com.google.android.gms.maps.internal.ao.a(:com.google.android.gms.alldynamite:74)
at maps.ei.bu.a(Unknown Source)
at maps.ei.r.a(Unknown Source)
at com.google.android.gms.maps.internal.IUiSettingsDelegate$zza.onTransact(:com.google.android.gms.alldynamite:66)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IMapViewDelegate$zza$zza.getMap(Unknown Source)
at com.google.android.gms.maps.MapView$zza.onInflate(Unknown Source)
at com.google.android.gms.dynamic.zza$3.zzb$6728a24f(Unknown Source)
at com.google.android.gms.dynamic.zza$1.zza(Unknown Source)
at com.google.android.gms.maps.MapView$zzb.zzvu(Unknown Source)
at com.google.android.gms.maps.MapView$zzb.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zzdY(Unknown Source)
at com.google.android.gms.dynamic.zza.zzdY(Unknown Source)
at com.google.android.gms.maps.MapView.onCreate(Unknown Source)
at com.android.fragments.MapFragment.newMap(SourceFile:2096)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1138)
at android.support.v4.app.FragmentManagerImpl.moveToState$2563266(SourceFile:1120)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:1929)
at android.support.v4.app.FragmentActivity.onStart(SourceFile:547)
at com.activities.FragmentActivity.onStart(SourceFile:255)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
at android.app.Activity.performStart(Activity.java:6268)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
来自我的PagerAdapter的instantiateItem看起来像这样:
public class CustomAdapter extends PagerAdapter {
public CustomAdapter(Context context) {
this.mContext = context;
}
@Override
public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
mViewPagerLayout = inflater.inflate(R.layout.custom_view_pager, collection, false);
mViewPagerLayout.setTag("pos" + position);
collection.addView(mViewPagerLayout);
return mViewPagerLayout;
}
CustomViewPager:
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context) {
super(context);
}
// more code
}
正在使用自定义视图寻呼机的xml:
<view xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
class="com.android.lib.views.WrapperView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.android.lib.views.CustomViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:clipToPadding="false"
android:paddingLeft="20dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:paddingRight="20dp"
android:visibility="gone"
tools:visibility="visible"/>
</view>
我在这里查看了解决方案ClassNotFoundException when unmarshalling: android.support.v4.view.ViewPager$SavedState,但这些是片段,但我使用View和PagerAdapter来保持它的重量轻。任何想法我能做什么?