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、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める