Fixed
Status Update
Comments
jg...@google.com <jg...@google.com>
ap...@google.com <ap...@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.
jg...@google.com <jg...@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()) {
...
}
```
jg...@google.com <jg...@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.")
Description
FragmentMaxLifecycleEnforcer method's updateFragmentMaxLifecycle doesn't guarantee current item will be paused before new one will be resumed.
for (int ix = 0; ix < mFragments.size(); ix++) {
long itemId = mFragments.keyAt(ix);
Fragment fragment = mFragments.valueAt(ix);
if (!fragment.isAdded()) {
continue;
}
transaction.setMaxLifecycle(fragment, itemId == mPrimaryItemId ? RESUMED : STARTED);
fragment.setMenuVisibility(itemId == mPrimaryItemId);
}
Implamentation depends on key order and doesn't enforce current item's lifecycle before new one.
So if I have fragment A and B:
- Moving from A to B will pause A and then resume B
- Moving from B to A will resume A and then pause B