Modernising a Legacy Android App Architecture: Part Three - Applying the Refactor
Article Summary
Rob Pridham from BBC Sport reveals how his team tackled a massive Android refactor—migrating from multiple activities to a single-activity architecture while keeping the app running in production.
This is the final installment of a three-part series documenting BBC Sport's Android app modernization. The team applied MVVM+C architecture across their legacy codebase while consolidating dozens of activities into a unified fragment hierarchy. The work spanned August to December 2020 alongside ongoing feature development.
Key Takeaways
- Fragment replace vs add strategy: memory concerns killed the add approach
- WebView state restoration proved trickiest: scroll position fights required creative workarounds
- Shared ViewModels across fragments enabled complex multi screen onboarding flows
- Navigation responsibility cleanup required UX changes to rationalize ambiguous parent contexts
- Feature flagged development allowed parallel work until migration reached critical mass
BBC Sport successfully refactored their legacy Android app to single-activity MVVM+C architecture, unlocking faster feature development despite significant WebView and navigation challenges.
About This Article
Rob Pridham's team found that using fragment add instead of replace left hidden fragments in memory that couldn't be garbage collected. This created a cluttered view hierarchy and caused unpredictable issues when fragments stacked on top of each other.
The team switched to using fragment replace, even though it meant fragments would be recreated. They used Android ViewModel scoping to keep state alive across recreations and relied on RecyclerView's built-in scroll position restoration through the architecture components framework.
Native fragment navigation automatically restored users to their previous scroll position and ViewModel state. WebView restoration was different though. It needed manual UUID-based state caching and custom scroll position logic to avoid multi-second loading delays and visual flicker.