Fixed
Status Update
Comments
jg...@google.com <jg...@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.
da...@gmail.com <da...@gmail.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()) {
...
}
```
je...@google.com <je...@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.")
je...@google.com <je...@google.com>
jg...@google.com <jg...@google.com>
je...@google.com <je...@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
je...@google.com <je...@google.com>
jg...@google.com <jg...@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.
Description
Issue found when `mCurrentItem` value is 1073742144. The result of `Math.abs(item - previousItem)` is 128 instead of 1, when the item we scroll to is 1073742145. This makes the ViewPager "pre-jump to nearby item for long jumps".