Modern Android Development
Language
Android Jetpack
- ViewModel
- LiveData
- Codelab
- Practice
- Room
- Codelab
- DataStore
- Codelab
- WorkManager
- Codelab
- Navigation
- Codelab
- CameraX
- Codelab
- Compose
- Course
- Codelab
Material Design
Clean Architecture in Android
- Presentation: Activities, Fragments, View Models, others view components.
- Domain: Use Cases, Entities, Repositories, others domain components.
- Data: Repository implementations, Mappers, DTO’s, etc.
Architecture Patterns for Presentation Layer
- MVVM
- MVI
Guide to app architecture
- Common architectural principles
- Separation of concerns: These UI-based classes(Activity, Fragment) should only contain logic that handles UI and operating system interactions. By keeping these classes as lean as possible, you can avoid many problems related to the component lifecycle, and improve the testability of these classes.
- Drive UI from data models(persistent models): Data models are independent from the UI elements and other components in your app. This means that they are not tied to the UI and app component lifecycle, but will still be destroyed when the OS decides to remove the app's process from memory.
- Single source of truth(SSOT): The SSOT is the owner of that data, and only the SSOT can modify or mutate it. To achieve this, the SSOT exposes the data using an immutable type, and to modify the data, the SSOT exposes functions or receive events that other types can call.
- Unidirectional Data Flow(UDF): The single source of truth principle is often used in our guides with the Unidirectional Data Flow (UDF) pattern. In UDF, state flows in only one direction. The events that modify the data flow in the opposite direction.
Recommended app architecture
- The UI layer that displays application data on the screen.
- The data layer that contains the business logic of your app and exposes application data.
(The arrows mean their dependency)
Modern App Architecture
- A reactive and layered architecture.
- Unidirectional Data Flow (UDF) in all layers of the app.
- A UI layer with state holders to manage the complexity of the UI.
- Coroutines and flows.
- Dependency injection best practices.
UI layer
- The role of the UI layer (or presentation layer) is to display the application data on the screen.
- The UI layer is made up of two things:
- UI elements that render the data on the screen. You build these elements using Views or Jetpack Compose functions.
- State holders (such as ViewModel classes) that hold data, expose it to the UI, and handle logic.
Data layer
- The data layer of an app contains the business logic. The business logic is what gives value to your app—it's made of rules that determine how your app creates, stores, and changes data.
- The data layer is made of repositories that each can contain zero to many data sources.
- Repository classes are responsible for the following tasks:
- Exposing data to the rest of the app.
- Centralizing changes to the data.
- Resolving conflicts between multiple data sources.
- Abstracting sources of data from the rest of the app.
- Containing business logic.
Domain layer
- The domain layer is responsible for encapsulating complex business logic, or simple business logic that is reused by multiple ViewModels.
General best practices
- Don't store data in app components(e.g. activities, fragment, services).
- Reduce dependencies on Android classes.
- Create well-defined boundaries of responsibility(single responsibility) between various modules in your app.
- Expose as little as possible from each module.
- Focus on the unique core of your app so it stands out from other apps.
- Consider how to make each part of your app testable in isolation.
- Types are responsible for their concurrency policy.
- Persist as much relevant and fresh data as possible.
Modern System Design
- A Simple Framework For Mobile System Design Interviews
- Typical Mobile System Design Interview Questions
- https://instagram-engineering.com/tagged/android