Skip to main content
InterviewHubPRO
Section Overview
Q4

Question 4 of 50

Part 1: Architecture, Jetpack Compose & Core Components (1 - 10)

8%
Android & Jetpack Compose (50 Qs)•Part 1: Architecture, Jetpack Compose & Core Components (1 - 10)

What is a ViewModel in Android Architecture Components and why does it survive configuration changes?

senior LevelComponentsDocker & ContainersSystem Design

In Simple Words: A ViewModel stores and manages UI-related data in a lifecycle-conscious way:

  • Configuration Change Problem: Rotating the phone or switching to dark mode destroys and recreates the Activity. Regular variables in the activity are lost!
  • ViewModel Lifecycle: The ViewModel remains retained in memory in the ViewModelStore throughout the configuration change until the Activity is permanently finished (onDestroy()), preventing redundant network requests and UI re-fetching.