bluelinelabs / bluelinelabs/Conductor
Bug (?) in save/restore instance state of ViewPager pages with RouterPagerAdapter
- Dominant language
- Java
- Stars
- 3.9k
- Forks
- 338
- PR merge metrics
- No merged PRs in 30d
Description
How can I prevent the following undesired behavior?
- A third page with state x=A is removed --> Conductor stores: 3->x=A
- Later, another new third page is added again with state x=B in constructor
- In restoreInstanceState() of the new third page x=B is overridden with x=A
My current workaround is `setMaxPagesToStateSave(0)` which is actually not what I want because then my data does not survive config changes or process death, right?
Calling `setMaxPagesToStateSave(getCount())` whenever the number of pages changed (to remove the state that has just been saved) does not help much either since in `ensurePagesSaved()` the line `savedPages.size() > maxPagesToStateSave` evaluates to false because `savedPages.size() == 1` (the removed third page) while `maxPagesToStateSave == 2` (the remaining 2 pages returned by getCount()).
Any idea/workaround/solution?
Any change to get this "fixed" by a more flexible Conductor mechanism?
Contributor guide
Research direction
Start by tracing ViewPager and RouterPagerAdapter state handling through setMaxPagesToStateSave(), ensurePagesSaved(), and restoreInstanceState(). Reproduce removal and re-add with x=A and x=B across state restoration; done means the replacement page does not inherit the removed page's state while state still survives configuration changes and process death.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100