Android is structured on a component basis, utilising components such as Activities, Fragments, and Services.
Android is responsible for managing these components.
We have been writing code in our android activities or fragments up to this point, for all types of tasks - ranging from data fetching to storing data in SQLite. The difficulty is situated here.
Difficulties on not Using Android Architecture Components
Components of Android should only be used for handling UI-related activities; they should not be employed to manage data. For instance, if the system is running with low memory, then the activity might get terminated, leading to a loss of stored data.
Whenever an alteration in configuration occurs, the Activity can be destroyed. This will result in the Oncreate() being called again and a recreation taking place, which will ultimately cause data to be lost. For example, if a user is logged in and they rotate their Android device, they would then be logged out.
Solution to Above Stated Problem
The JetPack library package includes Android Architecture Components, which enables us to separate the data from activities and thereby create data-driven applications.
Data Binding allows us to bind UI elements in our layout to data sources within the app.
LifeCycles manage activity and fragment lifecycles, survive configuration changes, and effortlessly load data into the UI.
Click here for Implementing LifeCycles in your Project.
LiveData notifies views of any changes made to the database.
Navigation manages all of the in-app navigation needs for Android applications.
Paging is helpful for gradually loading information from our data source as needed.
Room is a SQLite object mapping library that eliminates boilerplate code & quickly converts SQLite table data into Java objects with compile-time checks of SQLite statements & returns observables like RxJava, Flowable, & LiveData.
ViewModel stores UI-related data that isn't destroyed during app rotations in a lifecycle-conscious manner.
WorkManager manages background jobs based on our specifications for Android devices.
Creating a mental model of the Architecture Components, understanding how the pieces fit together and how data flows is the most important step in utilising and implementing the recommended architecture.
Thanks for reading!
Comentarios