Android

Android MVVM Architecture

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

18 คำถามสัมภาษณ์·
Mid-Level
1

What is a ViewModel in Android?

คำตอบ

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?

คำตอบ

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?

คำตอบ

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 คำถามสัมภาษณ์

เชี่ยวชาญ Android สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี