As the Android lead of a photo editor, would you build it as one activity hosting every screen or as several activities, and what decides it?
answer
- the platform's default recommendation
- one task, one window, one Bundle
- what a separate task buys
- manifest attributes are per activity
- migrate one flow at a time
basics
~20 sDefault to a single activity: screens become fragments or composables in one task, sharing state without launch modes. Add an activity only where the platform works per activity, such as a separate task in Recents or a different window setup.
solid answer
~50 sAndroid's guidance is that modern apps typically use a **single-activity architecture**: one `Activity` hosts the screens and a navigation library swaps them. For a photo editor that keeps in-app navigation inside one task and one `FragmentManager`, lets the gallery, editor and export screens share state and animate between each other, and removes most launch-mode and task-affinity puzzles. The costs are real: every screen writes into one activity's saved instance state, so an oversized total throws `TransactionTooLargeException`; the in-app back stack is the app's responsibility, not the system's; and manifest settings such as `windowSoftInputMode` or `configChanges` apply to every screen. I would add a second activity only where the platform works per activity: a project that should appear as its own task in Recents, a screen needing a different window or task setup, or a library that ships its own activity. An existing multi-activity app moves one flow at a time.
go deeper
Know that modern Android apps usually host their screens in one activity and swap fragments or composables inside it.
Explain what a single activity changes for the back stack, saved state and shared state between screens compared with one activity per screen.
Name the concrete cases that need another activity, such as a separate task or a different window setup, and the TransactionTooLargeException risk of one shared Bundle.
Own the default and its exceptions: document why each extra activity exists, budget saved state across screens, and plan an incremental migration with measurable steps.
## What the platform recommends The Android documentation says modern apps typically use a **single-activity architecture**: instead of starting a new `Activity` for every screen, the app hosts one activity and uses a navigation library to swap screens inside it, and for Compose it recommends a single activity throughout the app. With the View system the same idea uses fragments: one activity, a `FragmentContainerView`, and a `FragmentManager` back stack. The guidance is a default, not a law, and a lead's job is to know what it buys and where it stops fitting. ## What one activity buys - **One task and one window.** Moving from the gallery to the editor to the export screen never crosses an activity boundary, so `launchMode`, `taskAffinity` and intent flags stop being part of everyday navigation. - **Shared state across screens.** Screens of one flow can share a state holder scoped to the activity, in one clause a `ViewModel`, instead of passing data through intents and results. - **Transitions and back handling in-process.** Shared-element and custom animations between screens are fragment or composable transitions, and the back stack is one structure the app controls. - **Fewer entry points.** Fewer `<activity>` declarations means fewer components that could be exported to other apps by mistake. - **Testing a screen in isolation.** Fragments can be tested with `FragmentScenario`, passing a `FragmentFactory` for their dependencies, without launching the host activity's own setup. ## What it costs | Concern | Single activity | Several activities | |---|---|---| | Saved instance state | one `Bundle` collects every screen's state, so oversize risk is higher | each activity saves its own | | Back stack | managed by the app's `FragmentManager` or navigation library | managed by the system task | | Manifest attributes (`windowSoftInputMode`, `configChanges`, `theme`) | one setting for every screen | set per screen | | Process death | restores the activity, then its fragment or navigation stack | restores the task's activities one by one as the user goes back | | Entry from outside | the app routes the request to the right screen | an exported activity can be targeted directly | The saved-state point is the one interviewers expect: the platform warns that the size of the shared `Bundle` is limited and that storing large objects can cause `TransactionTooLargeException`, which is **particularly problematic in single-activity apps** where one `Bundle` is used across the app. A single-activity editor therefore needs a firm rule that screens save IDs, never documents or bitmaps. ## When a second activity earns its place Each of these is a case where the platform works per activity, not per screen: 1. **A separate task.** If each open project should appear in Recents on its own, the project screen needs its own activity, started into new tasks, for example with `singleInstancePerTask` plus `FLAG_ACTIVITY_MULTIPLE_TASK` or `FLAG_ACTIVITY_NEW_DOCUMENT`. 2. **A different window or task setup.** A full-screen capture screen with its own `configChanges` handling, its own soft-input behaviour or its own task affinity is simpler as a separate activity than as one screen fighting the host's settings. 3. **An entry point other apps start for a result.** An "edit this photo" activity that another app launches and expects a result from can be a small activity that runs the edit and returns, without dragging the whole app into the caller's task. 4. **A library that ships its own activity**, such as a sign-in or payment screen. Even then the rest of the app stays single-activity; this is not an all-or-nothing choice. ## Making the decision as a lead - **Start from the default.** New screens are fragments or composables in the existing host unless one of the cases above applies, and that exception is written down. - **Budget the shared Bundle.** Review what each screen saves, and test restoration with a real process kill, because one screen's oversized state crashes the whole app. - **Own the back stack.** With the system task no longer modelling every screen, the team must design what Back does on each screen and what stack a link from outside builds. - **Migrate incrementally.** An existing multi-activity editor moves one flow at a time: turn the screens of one flow into fragments in one host, keep the other activities, and retire them as their flows move. A big-bang rewrite adds risk without adding value. - **Keep the exported surface small.** Every activity left in the manifest is a reachable entry point to review. There is no single right answer for every app, but there is a defensible default, and a lead should be able to name the platform behaviour that justifies each extra activity.
- Your single-activity editor starts crashing with TransactionTooLargeException after a new feature ships. What do you check first?What the new screen writes into saved instance state, and how many such screens can sit on the back stack at once, since all of them share one activity's `Bundle`. Large lists, documents or bitmaps belong on disk or in an in-memory holder; the saved state should carry only IDs and small UI values. Then add a restoration test with a real process kill to the feature's checks.
- How do you move an existing multi-activity app toward a single activity without a rewrite?Pick one flow, such as editing, and host its screens as fragments in one activity while the rest of the app stays as it is. Keep the old activities as entry points until their flows move, so links and launcher shortcuts keep working. Each step ships on its own and can be verified, including Back behaviour and restoration after process death.
- Single activity means one giant activity class with every screen's logic.
- A single activity removes the need to handle process death.
- Every screen needs its own activity so the system Back button works.
- Launch modes are the right tool for navigating between in-app screens.
- Moving to a single activity has to be one big rewrite.