当前,我正在使用自定义LinearLayoutManger(StackLayoutManager),该代码为我的RecyclerView保存和检索一些int值,如下代码,
@Override
public Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putInt(KEY_TOTAL_OFFSET, mTotalOffset);
bundle.putParcelable(KEY_SUPER_SAVED_STATE, super.onSaveInstanceState());
return bundle;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
mTotalOffset = bundle.getInt(KEY_TOTAL_OFFSET, 0);
super.onRestoreInstanceState(bundle.getParcelable(KEY_SUPER_SAVED_STATE));
}
}
有时,在onRestoreInstanceState
上获取int波纹管时会引发错误,
Class not found when unmarshalling: android.support.v7.widget.LinearLayoutManager$SavedState
java.lang.ClassNotFoundException: android.support.v7.widget.LinearLayoutManager$SavedState
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at android.os.Parcel.readParcelableCreator(Parcel.java:2889)
at android.os.Parcel.readParcelable(Parcel.java:2843)
at android.os.Parcel.readValue(Parcel.java:2746)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3115)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273)
at android.os.BaseBundle.unparcel(BaseBundle.java:226)
at android.os.BaseBundle.getInt(BaseBundle.java:993)
at app.example.com.ui.StackLayoutManager.onRestoreInstanceState(StackLayoutManager.java:113)
at android.support.v7.widget.RecyclerView.onRestoreInstanceState(RecyclerView.java:1397)
at android.view.View.dispatchRestoreInstanceState(View.java:17850)
at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:3769)
at android.support.v7.widget.RecyclerView.dispatchRestoreInstanceState(RecyclerView.java:1414)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3755)
at android.view.View.restoreHierarchyState(View.java:17828)
at android.support.v4.app.Fragment.restoreViewState(Fragment.java:494)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1486)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at app.example.com.ui .DashboardActivity.onStart(DashboardActivity.java:227)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1413)
at android.app.Activity.performStart(Activity.java:7061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2874)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2989)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6753)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
我进行了搜索,但找不到与我的问题有关的任何解决方案