Status Update
Comments
si...@google.com <si...@google.com> #2
I found the root cause! The fragment savedstate class uses a null class loader. Come on, that's Android 101! The correct creator should be:
public static final Parcelable.Creator<SavedState> CREATOR
= new Parcelable.Creator<SavedState>() {
@Override
public SavedState createFromParcel(Parcel in) {
return new SavedState(in, getClass().getClassLoader()); // <------
}
@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
For wondering how to fix this, reflection will do the trick:
// TODOhttps://issuetracker.google.com/issues/74354091
val fragmentStateField: Field = Fragment.SavedState::class.java
.getDeclaredField("mState").apply {
isAccessible = true
}
// ...
(fragmentStateField.get(savedState) as Bundle).classLoader = javaClass.classLoader
public static final Parcelable.Creator<SavedState> CREATOR
= new Parcelable.Creator<SavedState>() {
@Override
public SavedState createFromParcel(Parcel in) {
return new SavedState(in, getClass().getClassLoader()); // <------
}
@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
For wondering how to fix this, reflection will do the trick:
// TODO
val fragmentStateField: Field = Fragment.SavedState::class.java
.getDeclaredField("mState").apply {
isAccessible = true
}
// ...
(fragmentStateField.get(savedState) as Bundle).classLoader = javaClass.classLoader
na...@gmail.com <na...@gmail.com> #3
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Android bug report
After reproducing the issue, press the volume up, volume down, and power button simultaneously. This will capture a bug report on your device in the “bug reports” directory. Attach the bug report file to this issue.
Alternate method:
After reproducing the issue, navigate to developer settings, ensure ‘USB debugging’ is enabled, then enable ‘Bug report shortcut’. To take bug report, hold the power button and select the ‘Take bug report’ option.
Android bug report
After reproducing the issue, press the volume up, volume down, and power button simultaneously. This will capture a bug report on your device in the “bug reports” directory. Attach the bug report file to this issue.
Alternate method:
After reproducing the issue, navigate to developer settings, ensure ‘USB debugging’ is enabled, then enable ‘Bug report shortcut’. To take bug report, hold the power button and select the ‘Take bug report’ option.
[Deleted User] <[Deleted User]> #4
Please provide the information requested in comment #3 to investigate this issue further.
si...@google.com <si...@google.com> #5
na...@gmail.com <na...@gmail.com> #6
nabrozidhs@, can you please provide the android bug report to confirm that is duplicate or not.
[Deleted User] <[Deleted User]> #7
You can see it on the issue link I posted on the previous email. Checking the stack trace both go through a ViewPager/FragmentStatePagerAdapter before failing on the same issue.
[Deleted User] <[Deleted User]> #8
Here, I have a simple sample which reproduces the issue: https://github.com/runningcode/classnotfound
Run `./gradlew connectedCheck` to reproduce.
The manual repro steps are as follows:
open an activity (with button)
press back
switch to 3rd tab
ppen activity again (with button)
Press back
switch back to 1st tab
This is very urgent to us. We are getting a lot of crashes because of this issue on support lib 27.1.0.
Run `./gradlew connectedCheck` to reproduce.
The manual repro steps are as follows:
open an activity (with button)
press back
switch to 3rd tab
ppen activity again (with button)
Press back
switch back to 1st tab
This is very urgent to us. We are getting a lot of crashes because of this issue on support lib 27.1.0.
[Deleted User] <[Deleted User]> #9
To clarify, the repro steps are only 100% reproducible on SDK 19 (Kitkat) but we are seeing it happen in production against all SDK levels.
si...@google.com <si...@google.com> #10
This bug has been fixed in Support Library 27.1.1.
ha...@gmail.com <ha...@gmail.com> #11
this is same in 28.0.2 show again, please help to fix it.thanks
wb...@gmail.com <wb...@gmail.com> #12
this is same in 28.0.0 show again。
=======
Fatal Exception: android.os.BadParcelableException:ClassNotFoundException when unmarshalling: android.support.v4.app.FragmentManagerState
at android.os.Parcel.readParcelableCreator(Parcel.java:2855)
at android.os.Parcel.readParcelable(Parcel.java:2781)
at android.os.Parcel.readValue(Parcel.java:2684)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3053)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:288)
at android.os.BaseBundle.unparcel(BaseBundle.java:232)
at android.os.BaseBundle.size(BaseBundle.java:350)
at android.app.servertransaction.LaunchActivityItem.hashCode(LaunchActivityItem.java:193)
at java.util.AbstractList.hashCode(AbstractList.java:541)
at java.util.Objects.hashCode(Objects.java:98)
at android.app.servertransaction.ClientTransaction.hashCode(ClientTransaction.java:236)
at java.lang.Object.toString(Object.java:273)
at java.lang.String.valueOf(String.java:2896)
at java.lang.StringBuilder.append(StringBuilder.java:132)
at android.os.Message.toStringLite(Message.java:533)
at android.os.Looper.loop(Looper.java:261)
at android.app.ActivityThread.main(ActivityThread.java:7154)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
=======
Fatal Exception: android.os.BadParcelableException:ClassNotFoundException when unmarshalling: android.support.v4.app.FragmentManagerState
at android.os.Parcel.readParcelableCreator(Parcel.java:2855)
at android.os.Parcel.readParcelable(Parcel.java:2781)
at android.os.Parcel.readValue(Parcel.java:2684)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3053)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:288)
at android.os.BaseBundle.unparcel(BaseBundle.java:232)
at android.os.BaseBundle.size(BaseBundle.java:350)
at android.app.servertransaction.LaunchActivityItem.hashCode(LaunchActivityItem.java:193)
at java.util.AbstractList.hashCode(AbstractList.java:541)
at java.util.Objects.hashCode(Objects.java:98)
at android.app.servertransaction.ClientTransaction.hashCode(ClientTransaction.java:236)
at java.lang.Object.toString(Object.java:273)
at java.lang.String.valueOf(String.java:2896)
at java.lang.StringBuilder.append(StringBuilder.java:132)
at android.os.Message.toStringLite(Message.java:533)
at android.os.Looper.loop(Looper.java:261)
at android.app.ActivityThread.main(ActivityThread.java:7154)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
zy...@gmail.com <zy...@gmail.com> #13
ma...@gmail.com <ma...@gmail.com> #14
The fix is to migrate the app to use AndroidX, instead of using the original support libraries.
Description
Version used: 27.1.0
Theme used: AppCompat
Devices/Android versions reproduced on: Nexus 5X with 8.1, Pixel with 8.1, Samsung with 7.1
At the moment I don't have time to create a sample app but these are the steps to reproduce the issue:
- create app with FragmentStatePagerAdapter with 4 tabs(tabLayout)
- create at least one view in each tab
- select 3rd tab
- put app in background
- kill app ( I used App Terminator )
- open app from recent
- click first tab
Sample stack trace
Fatal Exception: android.os.BadParcelableException
ClassNotFoundException when unmarshalling: android.support.v4.widget.NestedScrollView$SavedState
android.os.Parcel.readParcelableCreator (Parcel.java:2545)
android.support.v4.app.Fragment.setUserVisibleHint (Fragment.java:960)
com.dolly.helpers.screens.root.inbox.InboxFragment.setUserVisibleHint (InboxFragment.java:94)
android.support.v4.app.FragmentStatePagerAdapter.getItem (FragmentStatePagerAdapter.java:121)
android.support.v4.view.ViewPager.setCurrentItem (ViewPager.java:617)
com.dolly.helpers.screens.root.HomeFragment$1.onTabSelected (HomeFragment.java:136)
android.support.design.widget.TabLayout.dispatchTabSelected (TabLayout.java:1165)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)
As a workaround I currently use 27.0.2