Search code examples
androidmvvmandroid-architecture-componentsandroid-viewmodel

Use ViewModel in case other than Rotation


For what other purposes we can use ViewModel for?

I have been asked if an Activity is locked to portrait mode, then is this relevant to use ViewModel? If Yes why?


Solution

  • In general, ViewModel is an architectural component that "couples" a view with a model. From the architectural point of view it is relevant.

    Additionally to the general component, Android Jetpack's ViewModel is also lifecycle-aware. You can treat it as a conveniency bonus.

    With that being said, if the app is not supposed to have configuration changes (screen rotation is one of those) you may use any CustomViewModel.