Skip to content

Commit

Permalink
Store/retrieve saved state as a list.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jun 2, 2023
1 parent 2405684 commit 47c9105
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public Parcelable saveState() {
Bundle state = null;
if (!mSavedState.isEmpty()) {
state = new Bundle();
state.putParcelableArray("states", mSavedState.toArray(new Fragment.SavedState[0]));
state.putParcelableArrayList("states", mSavedState);
}
for (int i = 0; i < mFragments.size(); i++) {
final Fragment f = mFragments.get(i);
Expand All @@ -312,14 +312,12 @@ public void restoreState(@Nullable final Parcelable state, @Nullable final Class
if (state != null) {
final Bundle bundle = (Bundle) state;
bundle.setClassLoader(loader);
final Parcelable[] fss = BundleCompat.getParcelableArray(
bundle, "states", Parcelable.class);
final var states = BundleCompat.getParcelableArrayList(bundle, "states",
Fragment.SavedState.class);
mSavedState.clear();
mFragments.clear();
if (fss != null) {
for (final Parcelable parcelable : fss) {
mSavedState.add((Fragment.SavedState) parcelable);
}
if (states != null) {
mSavedState.addAll(states);
}
final Iterable<String> keys = bundle.keySet();
for (final String key : keys) {
Expand Down

0 comments on commit 47c9105

Please sign in to comment.