BBC Rob Pridham Dec 7, 2020

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

Critical Insight

BBC Sport successfully refactored their legacy Android app to single-activity MVVM+C architecture, unlocking faster feature development despite significant WebView and navigation challenges.

The team's biggest regret about the refactor wasn't technical—it was about how they communicated progress to non-engineers.

About This Article

Problem

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.

Solution

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.

Impact

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.