Presentation Layer
The presentation layer in Android is responsible for displaying data to the user and capturing user input.
In Android development, the presentation layer refers to the part of the architecture that handles the user interface (UI) and user experience (UX). This layer is responsible for displaying data to the user and capturing user interactions. It typically involves activities, fragments, view components, and view models. Here’s a more detailed breakdown:
ViewModels
The ViewModel class is a part of Android's architecture components and follows the MVVM (Model-View-ViewModel) design pattern. ViewModels store and manage UI-related data in a lifecycle-conscious way. They are responsible for preparing data for the UI and handling the business logic associated with user interactions. For example:
And if you're using jetpack compose, you can use StateFlow
. For example:
This MovieViewModel class provides a way to retrieve movie details using the movieUseCase and expose them to the UI layer through the detail live data variable. The detail() function can be called to trigger the retrieval of movie details for a specific movie ID.
Activities/Fragments
Activities are the main building blocks of the presentation layer. They represent a single screen in the application and contain the UI elements that the user interacts with. Fragments are modular pieces of UI that can be reused across multiple activities. They are similar to activities, but they do not have their own lifecycle.
observerLiveData
is onelib extension function for handling UI State.
Composable Function
A composable function is a key concept in Jetpack Compose, which is a modern toolkit for building native Android UI. Composable functions are annotated with @Composable
and define UI components in a declarative way. They are used to describe the UI and its behavior in a straightforward, readable, and reusable manner.
collectStateFlow
is onelib extension function for handling UI State for compose.
Last updated