Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

For most Android apps, start with two layers: a UI layer that renders state and handles interaction, and a data layer that owns application data and most business logic. Add a domain layer only when it clarifies complex rules or enables meaningful reuse. Keep each kind of data anchored to a clear source of truth, and make critical reads available locally if the app must work offline.

What Android app architecture should you start with?

Android’s architecture guidance recommends separating an app into a UI layer and a data layer, with an optional domain layer between them. These are design recommendations, not mandatory rules or a required number of Gradle modules. Adapt the structure to the app’s complexity and needs. Android’s architecture recommendations and its guide to app architecture describe this baseline.

  • UI layer: Displays application data and accepts user actions.
  • Data layer: Provides application data and contains most business logic, typically behind repositories.
  • Domain layer: Optional; holds reusable or complex business logic when it improves clarity.

A small app with straightforward behavior may need only the first two layers. The goal is to separate responsibilities so changes are easier to reason about and test—not to add abstractions for their own sake.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should data flow through the app?

Keep UI components focused on presentation and interaction. They should not access databases, network clients, or other data sources directly. Instead, a screen-level state holder, often a ViewModel, obtains data through the data layer and exposes state that the UI can render.

Android recommends unidirectional data flow: state moves toward the UI, and user actions travel back to the state holder. Collect observable state in a lifecycle-aware way so the app coordinates UI work with the screen’s lifecycle. A ViewModel is a common screen-level state holder, but the appropriate choice depends on the app. See Android’s UI layer guidance.

  1. The UI renders the current state it receives.
  2. The user takes an action, such as saving an item or refreshing a list.
  3. The UI passes that action to its state holder.
  4. The state holder requests work from the data layer, or from a domain layer if one is useful.
  5. The resulting data or status becomes new UI state, which the UI renders.

This separation gives presentation logic a clear boundary from data access. It also makes it easier to test data behavior without driving the UI.

When is a domain layer worth adding?

Add a domain layer when it solves a specific problem: for example, when the same business rule is used by multiple ViewModels, or when a ViewModel has accumulated enough logic to become difficult to understand. Use cases can give shared rules a clear home.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a simple operation used in one place, an extra layer may add indirection without improving the design. Android describes the domain layer as optional and most useful in larger apps where complexity or reuse justifies it. Do not treat Clean Architecture, a specific dependency-injection framework, or a fixed module layout as a requirement of the general Android architecture guidance.

How do repositories and sources of truth work?

A repository exposes and coordinates application data. It can combine sources, such as a local database and a network service, and decide how to resolve their results. A data-source class is narrower: it handles one source, such as a database, file, or network endpoint. Android’s data layer guidance recommends that each repository define a source of truth for the data it manages.

Make that choice explicit for each kind of data. In a network-backed app, the authoritative source may differ by feature. In an offline-first design, the local source is generally the source of truth for reads; remote changes are synchronized into it. This lets the app serve data without making every screen wait for a network response.

  1. List the app’s important data types and the features that read or change them.
  2. Choose one source of truth for each repository’s data.
  3. Keep access to individual sources behind data-source classes.
  4. Have repositories coordinate sources and expose data to the rest of the app.
  5. Define how the app represents updates, failures, and competing changes when the product requires it.

How should you design for offline use?

Offline support is a product decision as well as an architecture decision. Identify which reads are critical, then ensure they can be served from a local source without waiting for network access. Android’s offline-first guide recommends a local data source, such as a database, and says critical reads should work without network access.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When connectivity is unreliable, present available local data promptly and account for synchronization rather than treating the network as always available. The product determines how to communicate stale data, pending writes, synchronization status, or conflicting updates; there is no universal conflict-resolution policy for every app.

  • Decide which screens or actions must remain useful offline.
  • Use local data to serve those critical reads.
  • Plan how remote changes reach the local source and how updates are reflected in the UI.
  • Consider battery and data conditions when arranging fetches.
  • Choose product-specific behavior for stale content, failed writes, and conflicts.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How should foreground and background work differ?

Choose an operation’s execution approach based on its lifetime. Work directly tied to a screen can follow the lifecycle of the caller. Business-oriented work that should not depend on an individual UI caller has a different lifetime; Android’s data layer guidance on operation types recommends WorkManager for this class of operation.

Before moving work into the background, establish why it needs to continue beyond the screen or caller that started it. That distinction helps avoid coupling durable business work to a transient UI while keeping screen-specific work aligned with the UI lifecycle.

How can you apply the design in a real project?

  1. Map the feature. Identify its UI state, user actions, data types, and important business rules.
  2. Choose sources of truth. Decide which data source is authoritative for each repository, especially where local and remote data are both involved.
  3. Set layer boundaries. Keep rendering in the UI, coordinate data through repositories, and add domain logic only for complexity or reuse.
  4. Specify failure behavior. Decide what users see when data is stale, connectivity fails, a write is pending, or sources disagree.
  5. Match work to its lifetime. Keep screen-related work connected to its caller; use the recommended background-work approach for business operations that need a different lifetime.
  6. Test at the boundary that matters. Exercise business and data behavior independently of UI rendering, then verify that the UI presents the expected states.

Android Studio is Android’s official IDE. Its development environment includes Compose design tools, a build system, and the Android Emulator; Android’s Build your first app overview introduces the tools and learning pathway.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.