openedx-unsupported / edx-app-android

The Open edX mobile app for Android!
https://docs.google.com/document/d/15MYZ2LAmahB82P5wkPkQOqjszfou0Qkeae3qz7STxUQ/edit
Apache License 2.0
300 stars 336 forks source link

fix: TransactionTooLarge Exception caused by FragmentStateAdapter #1850

Closed HamzaIsrar12 closed 3 months ago

HamzaIsrar12 commented 3 months ago

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.

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

miankhalid commented 3 months ago

@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 commented 3 months ago

@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. 🏎️