Learning outcomes:
The elements of Android KOTLIN Applications and their architecture.
The elements of Android Kotlin applications are typically structured within a recommended architecture that ensures the development of robust, scalable, and maintainable apps.
The main elements and architecture of Android Kotlin applications include the key elements and architecture of Android Kotlin applications:
The 6 Key Elements of Android Application Architecture:
1. Activities and Fragments -
The core UI components that represent screens and portions of the UI.
2. Layouts and Views -
Define the structure and individual UI elements.
3. Intents -
Messaging objects used to request actions from other app components.
4. Services -
Background components for long-running operations.
5. Broadcast Receivers -
Components that respond to system-wide broadcast messages.
6. Content Providers -
Manage and share app data.
Architecture:
Android Kotlin apps typically follow an MVVM (Model-View-ViewModel) or Clean Architecture pattern.
This is similar to Model View Controller for Web Applications:
View : HTML, Android Screen: Point of Interaction with the User.
Controller: the set of classes which run the application: Deliver the Business Rules and Algorithms
Model: Data Store or data persistence layer. This is NOT the database itself. The Model is the wrapper or mediator that brokers connections to the database.
In the Android OS, there is a build in SQLite database. Accessible via the “Shared Preferences” Android Framework.
We also have the ROOMS Library.
With the following layers:
1. UI Layer
- Activities/Fragments are used to build ViewModels
2. Domain Layer: The “controller” - the system partition in which code business rules and algorithms: == Simplest Example here is the MainActivity.kt file : the file in which we code what happens
- Use Cases are boxes, descriptions of business processes, and how they Interact
3. Data Layer: The Persistence Layer
- Repositories
- Data Sources (local and remote)
This could be “on device” memory or remote API accessed memory.
Room Framework : built in SQLite db, good for storing preferences
MVVM Pattern: This architecture promotes:
Comparing MVC to MVVM: The big difference is:
In MVC: We do NOT allow Business Logic in the View Layer.
In MVVM, we put business logic in the view layer to simplify the design of the program.
- Separation of concerns
- Testability
- Maintainability
- Scalability
The ViewModel acts as a bridge between the UI and business logic.
The “Persistence Layer” (the connection to your database) manage data operations across multiple sources.
This layered approach allows for a clean separation between the UI, business logic, and data management.
This architecture enables building robust, maintainable Android applications in Kotlin by organizing code into logical layers with clear responsibilities.
Citations:
[1] https://developer.android.com/guide/components/fundamentals
[2] https://www.scaler.com/topics/basic-android-elements-in-kotlin/
[3] https://reintech.io/blog/implementing-mvvm-architecture-kotlin
[4] https://www.youtube.com/watch?v=4agk_yVY5z8
[5] https://github.com/emedinaa/kotlin-mvvm
[6] https://github.com/android10/Android-CleanArchitecture-Kotlin
[7] https://developer.android.com/topic/architecture
[8] https://developer.android.com/topic/libraries/architecture/viewmodel
[9] https://www.geeksforgeeks.org/components-android-application/
[10] https://kotlinlang.org/docs/android-overview.html
[11] https://www.toptal.com/android/android-apps-mvvm-with-clean-architecture
[12] https://dev.to/whatminjacodes/simple-example-of-mvvm-architecture-in-kotlin-4j5b
[13] https://www.geeksforgeeks.org/android-architecture/
[14] https://www.geeksforgeeks.org/mvvm-model-view-viewmodel-architecture-pattern-in-android/