Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

fix: TransactionTooLarge Exception caused by FragmentStateAdapter #1850

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

HamzaIsrar12
Copy link
Contributor

Description

LEARNER-9897

Previously, the FragmentStateAdapter was saving the state of the course dashboard view pager tabs upon navigation to the NavigationActivity. This behavior resulted in a TransactionTooLarge Exception when attempting to save the state in the bundle.

To mitigate this issue, we've made adjustments to the caching mechanism of the ViewPager2. Specifically, we've set the OffPage limit of the viewPager to ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT, which leverages the default caching mechanism of RecyclerView. This modification ensures efficient state handling and resolves the encountered exception.

Previously, the FragmentStateAdapter was saving the state of the
course dashboard view pager tabs upon navigation to the
NavigationActivity. This behavior resulted in a TransactionTooLarge
Exception when attempting to save the state in the bundle.

To mitigate this issue, we've made adjustments to the caching
mechanism of the ViewPager2. Specifically, we've set the OffPage
limit of the viewPager to ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT,
which leverages the default caching mechanism of RecyclerView.
This modification ensures efficient state handling and resolves the
encountered exception.

Fixes: LEARNER-9897
Copy link

codecov bot commented Mar 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 1.07%. Comparing base (89d8d4e) to head (7bfe8a7).

Additional details and impacted files
@@           Coverage Diff            @@
##             master   #1850   +/-   ##
========================================
  Coverage      1.07%   1.07%           
  Complexity      137     137           
========================================
  Files           539     539           
  Lines         26448   26446    -2     
  Branches       3412    3410    -2     
========================================
  Hits            284     284           
+ Misses        26137   26135    -2     
  Partials         27      27           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@miankhalid
Copy link
Contributor

@HamzaIsrar12 plz correct me if I'm wrong, we're currently saving data of 2 pages at any time other than the currently visible right?

if yes, how will the change you've made solve this problem? does it mean that no other page would be pre-loaded after this change?

@HamzaIsrar12
Copy link
Contributor Author

@miankhalid Previously, we ensured that all 6 pages were constantly retained on the course dashboard.

However, with the recent change, RecyclerView's mechanism ensures that all pages—both visible and some preceding and subsequent pages—are preloaded. Through observation, it's apparent that RecyclerView's retention mechanism excels over ViewPager's, effectively optimizing resource utilization without exceeding transaction limits.

In short, the UX behaviour remains unchanged. 🏎️

@HamzaIsrar12 HamzaIsrar12 merged commit 3667c60 into master Mar 27, 2024
4 checks passed
@HamzaIsrar12 HamzaIsrar12 deleted the hamza/LEARNER-9897 branch March 27, 2024 11:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants