Android

Android MVVM Architecture

MVVM Architecture with Jetpack: ViewModel, LiveData, Data Binding, Separation of Concerns, Unidirectional Data Flow

18 interview questionsยท
Mid-Level
1

What is a ViewModel in Android?

Answer

A ViewModel is a Jetpack component that stores and manages UI-related data in a lifecycle-aware way. It survives configuration changes (screen rotation) and allows separating business logic from UI.

2

How do you create a ViewModel instance in an Activity?

Answer

Use ViewModelProvider to create or retrieve a ViewModel instance. ViewModelProvider(this).get(MyViewModel.class) ensures you get the same instance even after screen rotation.

3

Why should you never pass an Activity or View Context into a ViewModel?

Answer

The ViewModel survives configuration changes and lives longer than Activities. Keeping an Activity Context reference would cause a memory leak. Use AndroidViewModel with Application Context if needed.

4

What is LiveData?

5

What is the difference between LiveData and MutableLiveData?

+15 interview questions

Master Android for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free