Posts

Showing posts with the label architecture

Exploring Android Navigation Architecture Component - MVVM - Kotlin

Image
Navigation Architecture Component is released as a part of JetPack and androidx package. Its aim is to simplify the implementation of Navigation in our Android App. It defines a set of principles to build an in-app navigation with consistent and predictable user experience. Its main concept is to use single-activity architecture. It also has support for both Activity and Fragment. Principle of Navigation: The following are the principles of Navigation. App should have fixed starting destination A stack is used to represent the navigation state of app The 'Up' button never exits the app Up and Back are equivalent within your app's task Deep linking to a destination or navigating to the same destination should yield the same stack You can find the detailed explanation, here . Components of Navigation: (i) Navigation Graph - It's nothing but a map/blueprint of our in-app navigation. It has a list of all fragments and activities. We can also

Room with LiveData, ViewModel - Android Architecture Components - Kotlin

Image
Introduction: We have already learnt about Room in last post,  Room-Kotlin . In this post, lets learn about how to use ViewModel and LiveData with Room to improve usablity. Using LiveData with Room, allows views to be notified about data changes automatically. LiveData: LiveData is nothing but observable data holder class. It allows us to observer changes in data across multiple components of app. It is also aware of and respects lifecycle of Activities/Fragments. It also ensures that LiveData only updates app component observers that are in an active lifecycle state. The following image depicts the Lifecycle and States: Here, CREATED, STARTED, RESUMED - Active States           INTIALIZED, DESTROYED - InActive States So, LiveData will remove the updates automatically while in InActive States, i.e., INTIALIZED and DESTROYED. ViewModel: ViewModel is an entity that is free of Activity/Fragment's lifecycle. So it allows us to store and manage UI-r

Android Architecture Components - Room - Kotlin

Image
Introduction: Google's Android Architecture components became stable now. It is nothing but a collection of libraries that ease our Android Development. Android Architecture Components: DataBinding Navigation Paging Library WorkManager LiveData & ViewModel Room Persistence Library Let's see about Room in this post.  Room is a new way to create a database in your Android Apps.  SQLite vs Room: The following are some of the advantages of Room over SQLite. (a) In SQLite, there is no compile-time verification of SQL queries, whereas Room verifies it. (b) We need to write lots of boilerplate codes to convert SQL queries to Java Objects. (c) We need to update the affected SQL queries manually, while the schema changes in SQLite. Whereas, Room will take care of it automatically. Room Architecure and Components: Three components are there in Room: (1) Database is a holder class that uses annotation to define the list of e