MVVM’s Model implementation in Android application. Room
What is Model in MVVM architecture?
As we said in the previous article Model is the data in our application. These are classes representing objects that we persist in our database or that we get from network calls to services. It is another name for the domain objects.
Persisting data locally in Android application
When it comes to persisting data locally in an Android application the only options are SharedPreferences and SQLite database. However SharedPreferences are good for storing user settings but they are not created for persisting large sets of data or relational data. So the only option for this kind of data is SQLite. Everybody who has previously used SQLite knows the pain of manually writing SQL statements for fetching and persisting data from the database, creating the tables manually, creating cursors for reading the data back and manually parsing the returned records to objects from our Model. Here Room comes to rescue.
What is Room?
- Using POJOs with annotations for schema for creating database tables
- Automatic object mapping from database records to POJOs and vice versa
- Out of the box implementation for the basic CRUD operations
- Exposing observables as query results – reactive programming
- Running CRUD operations on a background thread
Letzte Beiträge
Share :
Share :
Weitere Beiträge
LiveData
LiveData is an observable data holder class. It is also lifecycle-aware, which means that it respects the lifecycle of the other app components, such as activities, fragments and services. It notifies only active observers, represented by the Observer class.
6 Fragen an unseren Geschäftsführer Dimitar
Heute möchten wir euch Dimitar vorstellen, einen unserer zwei Geschäftsführer bei der DiSC. Er ist Spezialist für Mobile Netzwerke, Java Backend, Java Enterprise Edition sowie für Java Spring Boot
MVVM’s Model implementation in Android application. Room
As we said in the previous article Model is the data in our application. These are classes representing objects that we persist in our database or that we get from network calls to services.