Include this script into your page along with the iframe for a responsive media embed
In part 5 of the Architecture Components tutorial, we will create our Viewmodel class.nThe ViewModel works as a gateway between the UI controller and the repository. It stores and processes data for the activity/fragment and it doesn't get destoyed on configuration changes, so it doesn't lose it's variable state for example when the device is rotated.nBy extending AndroidViewModel, we get a handle to the application context, which we then use to instantiate our RoomDatabase.nIn our activity we let the system provide us the correct ViewModel instance by calling ViewModelProviders.of, where we pass the Activity or Fragment this ViewModel's lifecycle should be scoped to. When our Activity/Fragment is then destroyed, the ViewModel will go through it's onCleared method and get removed from the memory.nIn our activitie's onCreate method, we retrieve the LiveData that is stored in our ViewModel and call observe on it, where we pass a LifecycleOwner and an Observer. In the callback we get an update on our data whenever something in the corresponding database table changes. The LiveData will automatically start and stop sending updates to our activity at the right time in it's lifecycle and clean up any unused references.nnnWatch the whole playlist:nwww.youtube.com/playlist?list=PLrnPJCHvNZuDihTpkRs6SpZhqgBqPU118nnExample code, dependencies & instructions:ncodinginflow.com/tutorials/android/room-viewmodel-livedata-recyclerview-mvvm/part-5-viewmodelnn____________________nSubscribe to my channel:nwww.youtube.com/c/codinginflow?sub_confirmation=1nnWant more Android tutorials? Check my playlist section:nwww.youtube.com/c/codinginflow/playlistsnnnFollow me on social media:nnFacebook:nwww.facebook.com/codinginflownnInstagram:nhttps://www.instagram.com/codinginflownnTwitter:nhttps://twitter.com/codinginflownnBlog:nhttps://codinginflow.com/