skip to content

As Android lead of a large View-based app, in what order would you migrate screens to Jetpack Compose, and what rules would you set for the interop seam?

level: principalimportance: should knowfreq 45%

answer

  1. new features first
  2. a shared component library
  3. simple screens before complex ones
  4. one theme, one state owner per seam
  5. Fragment navigation stays until every destination is composable

basics

~20 s

Build new screens in Compose first, grow a shared component library, then replace existing screens one at a time, starting with simple ones. Set rules for the seam: one theme, a single state owner, a fixed disposal strategy, and AndroidView only where needed.

solid answer

~50 s

I follow the documented incremental path, then adjust for the app's risk profile. New features ship as Compose screens, inside a Fragment that returns a `ComposeView` while Fragment-based navigation remains. Reusable pieces go into a shared component library from day one. Existing screens are replaced one at a time, simple and static ones first, and mixed screens are finished bottom-up. Navigation moves to a Compose navigation library only once every destination is a composable. For the seam I set rules: every `ComposeView` wraps the same Compose theme mapped from the XML design tokens; Fragments use `DisposeOnViewTreeLifecycleDestroyed`; shared state lives in the screen's `ViewModel`, or with whichever side is closer to the root; `AndroidView` is reserved for components with no Compose equivalent; `AndroidViewBinding` only for small legacy layouts. Order within that path is a judgment call: traffic, churn, test coverage and the cost of keeping two UI stacks.

go deeper

for a junior

Recall the documented order: new screens in Compose, then shared components, then existing screens one at a time.

for a middle

Explain how a Fragment hosts a Compose screen with ComposeView and why navigation changes only after every destination is composable.

for a senior

Show how you keep the seam safe: one theme, explicit disposal strategies, a single state owner, and AndroidView reuse in lists.

for a principal

Own the ordering tradeoff of change rate, risk and test coverage, set seam rules the team reviews against, and drive to an end state instead of a permanent hybrid.

## The decision a lead owns Moving a large View-based app to Compose is not a single change; for months the app runs **two UI toolkits side by side**. The lead decides the **order** in which screens move and the **rules at the seam** where the two meet. Neither has one right answer. They depend on how often each screen changes, how well it is tested and how much risk the team can absorb. ## The documented path The Android migration guidance recommends incremental migration where Compose and Views coexist, in three moves: 1. **Build new screens with Compose.** New features are the cheapest place to adopt it. In a Fragment-based app, the new Fragment returns a `ComposeView` from `onCreateView`. 2. **Build a library of common UI components** as you go, so there is one source of truth for buttons, cards and typography, usable from Compose and, through `AbstractComposeView` wrappers, from View screens. 3. **Replace existing features one screen at a time**, starting with **simple screens** whose content is fairly static, such as a welcome, confirmation or settings screen. A screen that already has some Compose is finished **bottom-up** until it is entirely Compose. Navigation follows the screens: the guidance keeps the **Fragment-based Navigation component** until every destination is a composable, and only then moves to a Compose navigation library. ## Where judgment enters | Factor | Pushes a screen earlier | Pushes it later | |---|---|---| | Change rate | features land there every sprint | untouched for a year | | Complexity | static, few custom Views | heavy custom Views, complex scrolling | | Test coverage | UI tests already guard it | regressions would go unnoticed | | Dependencies | uses shared components already in Compose | needs a View-only SDK component | The guidance itself says to rely on UI testing to avoid regressions during migration, so a screen without tests may need tests first. ## Rules for the seam These are the standards a lead writes down and reviews against: - **One theme.** A Compose theme built on `MaterialTheme`, mapped from the XML theme's colours and typography, wraps every `setContent`. Material composables expect a `MaterialTheme` above them. - **Disposal per host.** Fragments call `setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)`; `RecyclerView` items keep the default. - **A single owner of shared state.** Prefer a `ViewModel` exposing a stream both sides observe. Inside a Fragment's `ComposeView`, `viewModel()` resolves the view tree's `ViewModelStoreOwner`, the Fragment, so it returns the same instance as the Fragment's own code. When state is tied to a UI element, the side closer to the root owns it: Compose publishes to View code with `SideEffect`, and View code holds shared values in `mutableStateOf`. - **AndroidView for gaps only.** The documentation reserves it for SDK components with no Compose equivalent and recommends rewriting custom Views, simplest first. In lists, require a non-null `onReset`. - **AndroidViewBinding is temporary.** Only for smaller legacy XML layouts during migration, never to inflate whole screens. - **Scroll and insets are decided once per screen.** Use the nested scroll interop connection where a Compose list sits under a `CoordinatorLayout`, and decide whether the View side or Compose consumes window insets. ## A sample plan for a karaoke-booking app 1. **Now:** the new "song request" feature ships as a Compose screen in a Fragment returning a `ComposeView`; its buttons and room cards become the first entries in the shared component library. 2. **Next quarter:** the confirmation and settings screens, static and well tested, are rewritten in Compose. 3. **Then:** the booking screen, already mixed with a Compose banner and a hosted XML form, is finished bottom-up: the form moves from `AndroidViewBinding` to composables, the legacy lyrics View is rewritten last because it is the most custom. 4. **Finally:** with every destination a composable, navigation moves off Fragments. Each step is reversible and ships on its own, which is the point: the team never stops delivering features while the toolkit changes underneath. ## What it costs to stop halfway A mixed app pays for both stacks: two theming systems to keep in sync, interop bugs at every seam, and engineers who must know both. The guidance notes that a Compose-only app can develop faster and reduce APK size and build time. A lead should therefore set an end state and track the share of screens migrated, rather than let the seam become permanent. ## A defensible answer - Order: new features, then shared components, then simple screens, then complex ones, then navigation. - Seam rules: one theme, explicit disposal, one state owner, minimal `AndroidView`. - Revisit the order whenever the change map or the test coverage shifts.

  • When should the team move off the Fragment-based Navigation component during this migration?
    Only once every navigation destination is a composable. Screen-level composables may still contain some View content through `AndroidView`, but until all Fragments are gone the guidance keeps the Fragment-based Navigation component, with each Compose screen hosted in a Fragment that returns a `ComposeView`.
  • A ComposeView banner and the surrounding Fragment code both need the booking state; which side should own it?
    Ideally neither: the Fragment's `ViewModel` exposes the state as a stream that both observe, and `viewModel()` inside the Fragment's `ComposeView` returns that same instance. If the state is tied to a UI element, the side closer to the root of the hierarchy owns it and pushes updates to the other.

  • Rewrite the whole app in Compose in one release before shipping features
  • Start the migration with the most complex, most custom screen
  • Switch to Compose navigation while most destinations are still Fragments
  • Each ComposeView can define its own ad hoc theme
  • Wrap every custom View in AndroidView permanently instead of rewriting it