Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Could be related to the changes you've made in FixedFragmentStateAdapter. Could you share the code, I can have a quick look.
il...@google.com <il...@google.com> #3
> Could be related to the changes you've made in FixedFragmentStateAdapter. Could you share the code, I can have a quick look.
Sorry, but I believe that is not a culprit. I just added a single line of code to avoid BadParcelableException.
https://issuetracker.google.com/issues/132840199
```
@Override
public final void restoreState(@NonNull Parcelable savedState) {
if (!mSavedStates.isEmpty() || !mFragments.isEmpty()) {
throw new IllegalStateException(
"Expected the adapter to be 'fresh' while restoring state.");
}
Bundle bundle = (Bundle) savedState;
bundle.setClassLoader(getClass().getClassLoader()); // <-- ADDED THIS LINE
for (String key : bundle.keySet()) {
...
}
```
Sorry, but I believe that is not a culprit. I just added a single line of code to avoid BadParcelableException.
```
@Override
public final void restoreState(@NonNull Parcelable savedState) {
if (!mSavedStates.isEmpty() || !mFragments.isEmpty()) {
throw new IllegalStateException(
"Expected the adapter to be 'fresh' while restoring state.");
}
Bundle bundle = (Bundle) savedState;
bundle.setClassLoader(getClass().getClassLoader()); // <-- ADDED THIS LINE
for (String key : bundle.keySet()) {
...
}
```
il...@google.com <il...@google.com> #4
I investigated the issue and turned out the part of the scenario which causes the problem;
1. RecyclerView.recycleViewHolderInternal()
2. hodler.doesTransientStatePreventRecycling() retuns true
3. FragmentStateAdapter.onFailedToRecycleView() -> onViewRecycled() -> removeFragment()
4. onFailedToRecycleView() retuns false, it means the ViewHolder is not recycled yet.
5. Soon after, FragmentStateAdapter.onViewAttachedToWindow() -> placeFragmentInViewHolder() -> IllegalStateException("Design assumption violated.")
1. RecyclerView.recycleViewHolderInternal()
2. hodler.doesTransientStatePreventRecycling() retuns true
3. FragmentStateAdapter.onFailedToRecycleView() -> onViewRecycled() -> removeFragment()
4. onFailedToRecycleView() retuns false, it means the ViewHolder is not recycled yet.
5. Soon after, FragmentStateAdapter.onViewAttachedToWindow() -> placeFragmentInViewHolder() -> IllegalStateException("Design assumption violated.")
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #5
Hi! I have successfully created a demo project which can reproduce this issue. Please check the following repo and I hope it helps to resolve the issue.
https://github.com/h6ah4i/FragmentStateAdapterOnFailedToRecyclerViewFailure
ap...@google.com <ap...@google.com> #6
[UPDATE]
This issue still exists on ViewPager2 v1.0.0-alpha06 with RecyclerView v1.1.0-beta01.
This issue still exists on ViewPager2 v1.0.0-alpha06 with RecyclerView v1.1.0-beta01.
ap...@google.com <ap...@google.com> #7
I can confirm I can repro this and will try to provide a workaround / fix soon.
Big thanks for the sample app, repro steps and research info. Super appreciated!
Big thanks for the sample app, repro steps and research info. Super appreciated!
jb...@google.com <jb...@google.com> #8
The easiest workaround would involve copying FragmentStateAdapter and FragmentViewHolder into your project, and in FragmentStateAdapter adding ensureFragment(holder.getAdapterPosition()) as the first line of placeFragmentInViewHolder method. Attached as a patch to your sample app.
We'll work on a proper fix. Might unblock you in the meantime though. Thanks again for reporting and a sample app.
We'll work on a proper fix. Might unblock you in the meantime though. Thanks again for reporting and a sample app.
Description
Version used: 1.4.0-alpha01
Devices/Android versions reproduced on: Android S
It's currently not possible to build an app which depends on fragment-testing for Android S since it depends on androidx.test:core:1.3.0 which does not properly export activities with intent filters.
androidx.test:core:1.4.0 fixes this.