Using ViewModel to Fix Screen Rotation Issues - Android Kotlin example

Опубликовано: 09 Октябрь 2024
на канале: Rahul Pandey
16,533
274

In this video, we walk through an example of adding a ViewModel in our Android app. ViewModels are a great way to ensure your app doesn’t have issues with screen rotation (portrait to landscape or vice versa), and there are additional benefits as well. ViewModels will help you pull data and logic out of Activities, which have a tendency to become monolith classes.

➤ Video walkthrough of base RecyclerView project:    • Kotlin RecyclerView Ep 1/3 Intro: 50 ...  
➤ Starter code: https://github.com/rpandey1234/Kotlin...
➤ Completed code: https://github.com/rpandey1234/Kotlin...

1:46 - Existing project and what changes we'll make
3:49 - Creating a new ViewModel class
8:00 - Adding swipe refresh layout

Other good videos:
➤ Android Developers video:    • Android Jetpack: ViewModel  
➤ MVVM architecture pattern:    • Model View View-Model (MVVM): Getting...  

References:
➤ Android reference for ViewModel: https://developer.android.com/topic/l...
➤ Codepath guide for SwipeRefreshLayout: https://guides.codepath.com/android/i...