Android

Android MVVM Architecture

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

18 câu hỏi phỏng vấn·
Mid-Level
1

What is a ViewModel in Android?

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Android cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí